Implement From<&Vec>
for Binary and HexBinary
#2036
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
To allow users access to the base64 and hex serialisation code used by Binary and HexBinary, allow casting reference to a vector into reference to the wrapper type. This is helpful when users needs some non-trivial serialisation which incorporates base64/hex. For example, consider (perhaps somewhat contrived) example of:
where we want
even_length
to use base64 encoding but also be guaranteed to be of even length. Since serialisation function takes the value by referenc, user would have to implement base64 encoding themselves. With this change, it’s possible to reuse Binary’s code:This conversion is added via bytemuck’s derive thus is guaranteed to be sound.
While adding it, also replace some manual implementations by use of derive_more’s derive macros to clean up code a little bit.