Skip to content

59 -- Use `RESPValueConvertible` as Generic Constraint

Nathan Harris requested to merge 59-respconvertible-generics into 47-proposal-feedback

Motivation:

Johannes continues to provide great insight, and correctly pointed out that RESPValueConvertible was being used as an "existential" in all cases.

This can cause unexpected type-erasure and introduce unnecessary cost overhead with dynamic dispatch when in most cases we know the exact value we want for RESPValue to execute commands.

Modifications:

  • Add new extensions to Array where Element == RESPValue for appending and adding elements into them
  • Change RedisClient.send(command:with:) to require [RESPValue] instead of [RESPValueConvertible] as the with argument type
  • Change all instances of RESPValueConvertible being an "existential" type for method arguments to instead be a generic constraint

Result:

The library should be safeguarded from a class of bugs, with the use of send being a bit more straight forward, with some new convenience methods for [RESPValue] types.

Closes #59 (closed)

Merge request reports

Loading