Skip to content
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

Closed
wants to merge 1 commit into from

Commits on Dec 22, 2020

  1. Make it easy to access the contents of any hash (newtype)

    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 us
    to convert to the inner representation.
    
    Both of these changes are especially useful from a broader ecosystem
    perspective:
    
    Because `From` and `Into` are part of the standard library, any
    application 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.
    thomaseizinger committed Dec 22, 2020
    Configuration menu
    Copy the full SHA
    13ab752 View commit details
    Browse the repository at this point in the history