StableHasher

Trait StableHasher 

Source
pub trait StableHasher {
    type Out;
    type Addr: FieldAddress;
    type Bytes: AsRef<[u8]>;

    // Required methods
    fn new() -> Self;
    fn write(&mut self, field_address: Self::Addr, bytes: &[u8]);
    fn mixin(&mut self, other: &Self);
    fn finish(&self) -> Self::Out;
    fn to_bytes(&self) -> Self::Bytes;
    fn from_bytes(bytes: Self::Bytes) -> Self;

    // Provided method
    fn unmix(&mut self, _other: &Self) { ... }
}
Expand description

Like Hasher, but consistent across:

  • builds (independent of rustc version or std implementation details)
  • platforms (eg: 32 bit & 64 bit, x68 and ARM)
  • processes (multiple runs of the same program)

Required Associated Types§

Source

type Out

The type of value returned when finishing

Source

type Addr: FieldAddress

The type used when identifying where a value is located in a struct

Source

type Bytes: AsRef<[u8]>

Used when serializing

Required Methods§

Source

fn new() -> Self

Create an empty hasher

Source

fn write(&mut self, field_address: Self::Addr, bytes: &[u8])

Add a single field to the hash

Source

fn mixin(&mut self, other: &Self)

Adds all fields from another hasher

Source

fn finish(&self) -> Self::Out

Finalize the digest

Source

fn to_bytes(&self) -> Self::Bytes

Serialize

Source

fn from_bytes(bytes: Self::Bytes) -> Self

Deserialize

Provided Methods§

Source

fn unmix(&mut self, _other: &Self)

Removes all fields from another hasher

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§