pub trait Hasher<const S: usize>:
Default
+ Send
+ Sync {
type Digest: Digest<S>;
const SIZE: usize = S;
// Required method
fn digest(input: &[u8]) -> Self::Digest
where Self: Sized;
}
Expand description
Trait implemented by a hash function implementation.
It specifies its own Digest type, so that the output of the hash function
can later be distinguished. This way you can create a MultihashDigest
from a Digest
.
Every hashing algorithm that is used with Multihash needs to implement
those. This trait is very similar to the external digest::Digest
trait.
There is a small significant difference, which needed the introduction of
this Hasher
trait instead of re-using the widely used digest::Digest
trait.
The external digest::Digest
trait has a single return type called
Output
, which is used for all hashers that implement it. It’s basically
a wrapper around the hashed result bytes. For Multihashes we need to
distinguish those bytes, as we care about which hash function they
were created with (which is the whole point of Multihashes). Therefore the
Hasher
trait defines an associated type Hasher::Digest
for the
output of the hasher. This way the implementers can specify their own,
hasher specific type (which implements Digest
) for their output.
Provided Associated Constants§
Required Associated Types§
Required Methods§
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.