Derive Macro ByteHash
#[derive(ByteHash)]
{
// Attributes available to this derive:
#[zerocopy]
}
Expand description
Derives an optimized Hash
implementation.
This derive can be applied to structs and enums implementing both
Immutable
and IntoBytes
; e.g.:
#[derive(ByteHash, Immutable, IntoBytes)]
#[repr(C)]
struct MyStruct {
...
}
#[derive(ByteHash, Immutable, IntoBytes)]
#[repr(u8)]
enum MyEnum {
...
}
The standard library’s derive(Hash)
produces hashes by
individually hashing each field and combining the results. Instead, the
implementations of Hash::hash()
and Hash::hash_slice()
generated by
derive(ByteHash)
convert the entirey of self
to a byte slice and hashes
it in a single call to Hasher::write()
. This may have performance
advantages.