pub struct IntHasher<T>(/* private fields */);Expand description
For an enabled type T, a IntHasher<T> implements std::hash::Hasher and
uses the value set by one of the write_{u8, u16, u32, u64, usize, i8, i16, i32, i64, isize} methods as its hash output.
IntHasher does not implement any hashing algorithm and can only be used
with types which can be mapped directly to a numeric value. Out of the box
IntHasher is enabled for u8, u16, u32, u64, usize, i8, i16,
i32, i64, and isize. Types that should be used with IntHasher need
to implement IsEnabled and by doing so assert that their Hash impl invokes
only one of the Hasher::write_{u8, u16, u32, u64, usize, i8, i16, i32, i64, isize} methods exactly once.
§Examples
See also BuildIntHasher, IntMap and IntSet for some easier
usage examples. See IsEnabled for use with custom types.
use integer_hasher::IntHasher;
use std::{collections::HashMap, hash::BuildHasherDefault};
let mut m: HashMap::<u8, char, BuildHasherDefault<IntHasher<u8>>> =
HashMap::with_capacity_and_hasher(2, BuildHasherDefault::default());
m.insert(0, 'a');
m.insert(1, 'b');
assert_eq!(Some(&'a'), m.get(&0));
assert_eq!(Some(&'b'), m.get(&1));Trait Implementations§
Source§impl<T: IsEnabled> Hasher for IntHasher<T>
impl<T: IsEnabled> Hasher for IntHasher<T>
Source§fn write_usize(&mut self, n: usize)
fn write_usize(&mut self, n: usize)
usize into this hasher.Source§fn write_isize(&mut self, n: isize)
fn write_isize(&mut self, n: isize)
isize into this hasher.1.26.0 · Source§fn write_u128(&mut self, i: u128)
fn write_u128(&mut self, i: u128)
u128 into this hasher.1.26.0 · Source§fn write_i128(&mut self, i: i128)
fn write_i128(&mut self, i: i128)
i128 into this hasher.Source§fn write_length_prefix(&mut self, len: usize)
fn write_length_prefix(&mut self, len: usize)
hasher_prefixfree_extras)