Skip to main content

ParallelDigest

Trait ParallelDigest 

Source
pub trait ParallelDigest: Send {
    type Digest: Digest;

    // Required methods
    fn new() -> Self;
    fn digest<I: IntoIterator<Item: SerializeBytes>>(
        &self,
        source: impl IndexedParallelIterator<Item = I>,
        out: &mut [MaybeUninit<Output<Self::Digest>>],
    );

    // Provided method
    fn digest_with_const_len<I: IntoIterator<Item: FixedSizeSerializeBytes>>(
        &self,
        n_items_per_input: usize,
        source: impl IndexedParallelIterator<Item = I>,
        out: &mut [MaybeUninit<Output<Self::Digest>>],
    ) { ... }
}

Required Associated Types§

Source

type Digest: Digest

The corresponding non-parallelized hash function.

Required Methods§

Source

fn new() -> Self

Create new hasher instance with empty state.

Source

fn digest<I: IntoIterator<Item: SerializeBytes>>( &self, source: impl IndexedParallelIterator<Item = I>, out: &mut [MaybeUninit<Output<Self::Digest>>], )

Calculate the digest of multiple hashes by processing a parallel iterator of iterators.

The source parameter provides a parallel iterator where:

  • Each element of the outer iterator maps to one leaf/digest in the output
  • Each element contains an inner iterator of items that will be serialized and concatenated to form that leaf’s content
§Panics

All items must be able to serialize with SerializationMode::Native without error, or this method will panic.

Provided Methods§

Source

fn digest_with_const_len<I: IntoIterator<Item: FixedSizeSerializeBytes>>( &self, n_items_per_input: usize, source: impl IndexedParallelIterator<Item = I>, out: &mut [MaybeUninit<Output<Self::Digest>>], )

Like digest, but specialized for the case where every leaf is built from exactly n_items_per_input items of a [FixedSizeSerializeBytes] type, so that each leaf has the same, compile-time-derivable byte length.

This extra structure lets implementations skip per-leaf length bookkeeping (and, for short leaves, the message padding) that digest must redo every time. The default implementation simply forwards to digest.

§Panics

Each iterator in source must yield exactly n_items_per_input items, and all items must serialize without error, or this method may panic.

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 ParallelDigest for ParallelSha256Digest

Source§

type Digest = Sha256

Source§

impl<D> ParallelDigest for ParallelDigestAdapter<D>
where D: Digest + FixedOutputReset + BlockSizeUser + Send + Sync + Clone,

Source§

impl<D: MultiDigest<N, Digest: Send> + Send + Sync, const N: usize> ParallelDigest for ParallelMultidigestImpl<D, N>