Skip to main content

Hash

Trait Hash 

Source
pub trait Hash {
    type Out: Copy + Eq + Debug;

    // Required method
    fn hash(bytes: &[u8]) -> Self::Out;

    // Provided method
    fn hash_pair(a: &[u8], b: &[u8]) -> Self::Out { ... }
}
Expand description

Hash function abstraction.

Implementations are stateless types (typically unit structs); hash is a pure function from bytes to a fixed-size digest.

Required Associated Types§

Source

type Out: Copy + Eq + Debug

Digest type. Must be Copy for use in BMT and cap fields.

Required Methods§

Source

fn hash(bytes: &[u8]) -> Self::Out

Hash a byte slice.

Provided Methods§

Source

fn hash_pair(a: &[u8], b: &[u8]) -> Self::Out

Hash the concatenation of two byte slices, without materializing the concatenation. Default impl just allocates; implementations should override for efficiency where possible.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§