pub struct NoHashHasher<T>(/* private fields */);
Expand description
For an enabled type T
, a NoHashHasher<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.
NoHashHasher
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
NoHashHasher
is enabled for u8
, u16
, u32
, u64
, usize
, i8
, i16
,
i32
, i64
, and isize
. Types that should be used with NoHashHasher
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 BuildNoHashHasher
, IntMap
and IntSet
for some easier
usage examples. See IsEnabled
for use with custom types.
use nohash_hasher::NoHashHasher;
use std::{collections::HashMap, hash::BuildHasherDefault};
let mut m: HashMap::<u8, char, BuildHasherDefault<NoHashHasher<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> Clone for NoHashHasher<T>
impl<T> Clone for NoHashHasher<T>
Source§impl<T> Debug for NoHashHasher<T>
impl<T> Debug for NoHashHasher<T>
Source§impl<T> Default for NoHashHasher<T>
impl<T> Default for NoHashHasher<T>
Source§impl<T: IsEnabled> Hasher for NoHashHasher<T>
impl<T: IsEnabled> Hasher for NoHashHasher<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
)impl<T> Copy for NoHashHasher<T>
Auto Trait Implementations§
impl<T> Freeze for NoHashHasher<T>
impl<T> RefUnwindSafe for NoHashHasher<T>where
T: RefUnwindSafe,
impl<T> Send for NoHashHasher<T>where
T: Send,
impl<T> Sync for NoHashHasher<T>where
T: Sync,
impl<T> Unpin for NoHashHasher<T>where
T: Unpin,
impl<T> UnwindSafe for NoHashHasher<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)