Struct astral::util::hash::NopHasher

pub struct NopHasher { /* private fields */ }
Expand description

An implementation of Hasher hasher which only accepts values with a size of 8 bytes or an integral value fitting into 8 bytes.

Panics

Panics if values with a size greater than 8 bytes are passed in.

Examples

Usage:

use std::hash::{Hash, Hasher};

use astral::util::hash::NopHasher;

let mut hasher = NopHasher::default();
1234_5678_u32.hash(&mut hasher);
assert_eq!(hasher.finish(), 1234_5678);

Slices and arrays cannot be hashed directly, since their len is also hashed. Hash::hash_slice may be used instead:

use std::hash::{Hash, Hasher};

use astral::util::hash::NopHasher;

let mut hasher = NopHasher::default();
let arr = [0x12_u8, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0];
Hash::hash_slice(&arr, &mut hasher);
assert_eq!(hasher.finish(), 0x1234_5678_9ABC_DEF0_u64.to_be());

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Returns the hash value for the values written so far. Read more
Writes some data into this Hasher. Read more
Writes a single u8 into this hasher.
Writes a single u16 into this hasher.
Writes a single u32 into this hasher.
Writes a single usize into this hasher.
Writes a single i8 into this hasher.
Writes a single i16 into this hasher.
Writes a single i32 into this hasher.
Writes a single isize into this hasher.
Writes a single u64 into this hasher.
Writes a single u128 into this hasher.
Writes a single i64 into this hasher.
Writes a single i128 into this hasher.
🔬This is a nightly-only experimental API. (hasher_prefixfree_extras)
Writes a length prefix into this hasher, as part of being prefix-free. Read more
🔬This is a nightly-only experimental API. (hasher_prefixfree_extras)
Writes a single str into this hasher. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.