pub trait MultihashCode:
TryFrom<u64>
+ Into<u64>
+ Send
+ Sync
+ Unpin
+ Copy
+ Eq
+ Debug
+ 'static {
type AllocSize: Size;
// Required methods
fn digest(&self, input: &[u8]) -> Multihash<Self::AllocSize>;
fn multihash_from_digest<'a, S, D>(
digest: &'a D,
) -> Multihash<Self::AllocSize>
where S: Size,
D: Digest<S>,
Self: From<&'a D>;
}
Expand description
Trait that implements hashing.
It is usually implemented by a custom code table enum that derives the Multihash
derive.
Required Associated Types§
Required Methods§
Sourcefn digest(&self, input: &[u8]) -> Multihash<Self::AllocSize>
fn digest(&self, input: &[u8]) -> Multihash<Self::AllocSize>
Calculate the hash of some input data.
§Example
// `Code` implements `MultihashCode`
use tiny_multihash::{Code, MultihashCode};
let hash = Code::Sha3_256.digest(b"Hello world!");
println!("{:02x?}", hash);
Sourcefn multihash_from_digest<'a, S, D>(digest: &'a D) -> Multihash<Self::AllocSize>
fn multihash_from_digest<'a, S, D>(digest: &'a D) -> Multihash<Self::AllocSize>
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.