Skip to main content

StateHasher

Struct StateHasher 

Source
pub struct StateHasher { /* private fields */ }
Expand description

An explicit BLAKE3 writer for deterministic state.

The encoding is schema-driven: each write appends its fixed-width little-endian bytes without a type tag, and bytes and sequence prefix a u32 length. The schema is the shape of the primitive writes: which methods, in what order. Write sequences with the same schema hash differently whenever their values differ, provided each CanonicalWrite it uses is self-delimiting. Different schemas may encode alike — u16(0x1234) equals u8(0x34); u8(0x12) — so a caller that hashes several kinds of state in one stream, or changes what it writes, separates them itself with a leading tag or version (for example u32(KIND)).

Implementations§

Source§

impl StateHasher

Source

pub fn new() -> Self

Creates an empty state hasher.

Source

pub fn u8(&mut self, value: u8)

Appends one byte.

Source

pub fn u16(&mut self, value: u16)

Appends a two-byte little-endian integer.

Source

pub fn u32(&mut self, value: u32)

Appends a four-byte little-endian integer.

Source

pub fn u64(&mut self, value: u64)

Appends an eight-byte little-endian integer.

Source

pub fn i32(&mut self, value: i32)

Appends a signed four-byte little-endian integer.

Source

pub fn i64(&mut self, value: i64)

Appends a signed eight-byte little-endian integer.

Source

pub fn bool(&mut self, value: bool)

Appends a boolean as exactly 0 or 1.

Source

pub fn bytes(&mut self, bytes: &[u8])

Appends bytes preceded by their checked u32 length.

Source

pub fn length(&mut self, length: usize)

Appends a collection length as u32.

§Panics

Panics when length cannot be represented in the frozen format.

Source

pub fn write<T: CanonicalWrite + ?Sized>(&mut self, value: &T)

Appends a canonical value.

Source

pub fn sequence<T: CanonicalWrite>(&mut self, values: &[T])

Appends an ordered sequence with a u32 length prefix.

Source

pub fn finish(self) -> Digest

Finalizes the digest.

Trait Implementations§

Source§

impl Default for StateHasher

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.