This repository has been archived by the owner on Nov 30, 2022. It is now read-only.
Make it easy to access the contents of any hash (newtype) #81
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.
Hashes can be represented as fixed length arrays. That is in fact
what they are internally.
There is value in using Rust's visibility rules to enforce that
no every byte array is a valid hash.
However, every hash is certainly a valid byte array, hence it
should be easy to access their contents as such.
We add a
From
impl for any hash newtype for the inner byte array.This makes it possible to pass hash-newtypes the way they are to
any function that needs a byte-array.
We also add a
From
impl for any inner hash type that allows usto convert to the inner representation.
Both of these changes are especially useful from a broader ecosystem
perspective:
Because
From
andInto
are part of the standard library, anyapplication or crate depends on them and can write functions that
support a form of method overloading by accepting anything that is
Into<[u8; 32]>
.Implementing these conversion traits on our types makes them
compatible with this pattern which results in less verbose APIs.