Skip to content

Conversation

@tarcieri
Copy link
Member

Closes #527.

Adds generic wrapper types for encoding references to types which impl encoding traits:

  • EncodeRef: impls Encode for &T where T: Encode
  • EncodeValueRef: impls EncodeValue and Tagged for &T

This, in conjunction with impls for &Option<T>, eliminates the need to have a dedicated OptionalRef type.

The ContextSpecificRef type is retained as it's a useful constructor for use in proc macros.

All in all it would be nice to have a better solution like this, like a blanket impl of Encode for &T where T: Encode. That's a direction which may still be worth exploring, but in the meantime the wrapper types mean there's a generic solution for reference type encoding.

Adds generic wrapper types for encoding references to types which impl
encoding traits:

- `EncodeRef`: impls `Encode` for &T where T: `Encode`
- `EncodeValueRef`: impls `EncodeValue` and `Tagged` for &T

This, in conjunction with impls for `&Option<T>`, eliminates the need
to have a dedicated `OptionalRef` type.

The `ContextSpecificRef` type is retained as it's a useful constructor
for use in proc macros.

All in all it would be nice to have a better solution like this, like a
blanket impl of `Encode` for &T where T: `Encode`. That's a direction
which may still be worth exploring, but in the meantime the wrapper
types mean there's a generic solution for reference type encoding.
@tarcieri tarcieri merged commit 677bc84 into master Apr 23, 2022
@tarcieri tarcieri deleted the der/encode-ref branch April 23, 2022 18:04
@tarcieri tarcieri mentioned this pull request Apr 23, 2022
5 tasks
@tarcieri tarcieri mentioned this pull request May 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

der: generalized EncodeValue support for references

2 participants