Skip to main content

StableHasher

Struct StableHasher 

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

FNV-1a, 64-bit, specified here rather than borrowed.

Fingerprints are written into .dry4rust-ignore.toml and are expected to still match the next time the tool runs – possibly under a different toolchain. DefaultHasher cannot promise that: the standard library says its algorithm is unspecified and not to be relied upon across releases. A suppression that silently stops matching is the worst kind of failure, because the duplicate simply reappears with no explanation.

So the algorithm lives here, in eight lines anyone can check against the published FNV specification, and every integer is written big-endian at a fixed width so that a 32-bit machine and a 64-bit one agree.

Implementations§

Source§

impl StableHasher

Source

pub const fn new() -> Self

Source

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

Absorb raw bytes.

Source

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

Absorb a single byte.

Source

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

Absorb an integer, big-endian and eight bytes wide regardless of the platform’s word size.

Source

pub const fn write_str(&mut self, value: &str)

Absorb a string, length first.

The length prefix is what keeps ("ab", "c") from hashing the same as ("a", "bc"), which matters because variant names are written one after another with nothing between them.

Source

pub const fn finish(&self) -> u64

The hash of everything absorbed so far.

Trait Implementations§

Source§

impl Default for StableHasher

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.