Trait HasherDigest

Source
pub trait HasherDigest:
    Digest<OutputSize = Self::OutSize>
    + Write
    + Send
    + Sync {
    type OutSize: ArrayLength<u8, ArrayType = Self::ArrayType>;
    type ArrayType: Copy;
}
Expand description

Convenience trait and blanket impl for downstream trait bounds.

Useful for downstream code that’s generic over [Digest] hasher H.

§Example

Do this:

fn generic_over_hasher<H>()
where
    H: HasherDigest,
{
    let my_data = [1, 2, 3, 4, 5, 6, 7, 8, 9];
    let mt = HasherMerkleTree::<H, usize>::from_elems(None, &my_data).unwrap();
}

Instead of this:

fn generic_over_hasher<H>()
where
    H: Digest + Write + Send + Sync,
    <<H as OutputSizeUser>::OutputSize as ArrayLength<u8>>::ArrayType: Copy,
{
    let my_data = [1, 2, 3, 4, 5, 6, 7, 8, 9];
    let mt = HasherMerkleTree::<H, usize>::from_elems(None, &my_data).unwrap();
}

Note that the complex trait bound for Copy is necessary:

fn generic_over_hasher<H>()
where
    H: Digest + Write + Send + Sync,
{
    let my_data = [1, 2, 3, 4, 5, 6, 7, 8, 9];
    let mt = HasherMerkleTree::<H, usize>::from_elems(None, &my_data).unwrap();
}

Required Associated Types§

Source

type OutSize: ArrayLength<u8, ArrayType = Self::ArrayType>

Type for the output size

Source

type ArrayType: Copy

Type for the array

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§

Source§

impl<T> HasherDigest for T
where T: Digest + Write + Send + Sync, <T::OutputSize as ArrayLength<u8>>::ArrayType: Copy,

Source§

type OutSize = <T as OutputSizeUser>::OutputSize

Source§

type ArrayType = <<T as HasherDigest>::OutSize as ArrayLength<u8>>::ArrayType