Trait IsEnabled

Source
pub trait IsEnabled { }
Expand description

Types which are safe to use with IntHasher.

This marker trait is an option for types to enable themselves for use with IntHasher. In order to be safe, the Hash impl needs to satisfy the following constraint:

One of the Hasher::write_{u8,u16,u32,u64,usize,i8,i16,i32,i64,isize} methods is invoked exactly once.

The best way to ensure this is to write a custom Hash impl even when deriving Hash for a simple newtype of a single type which itself implements IsEnabled may work as well.

§Example

#[derive(PartialEq, Eq)]
struct SomeType(u32);

impl std::hash::Hash for SomeType {
    fn hash<H: std::hash::Hasher>(&self, hasher: &mut H) {
        hasher.write_u32(self.0)
    }
}

impl integer_hasher::IsEnabled for SomeType {}

let mut m = integer_hasher::IntMap::default();

m.insert(SomeType(1), 't');
m.insert(SomeType(0), 'f');

assert_eq!(Some(&'t'), m.get(&SomeType(1)));
assert_eq!(Some(&'f'), m.get(&SomeType(0)));

Implementations on Foreign Types§

Source§

impl IsEnabled for i8

Source§

impl IsEnabled for i16

Source§

impl IsEnabled for i32

Source§

impl IsEnabled for i64

Source§

impl IsEnabled for isize

Source§

impl IsEnabled for u8

Source§

impl IsEnabled for u16

Source§

impl IsEnabled for u32

Source§

impl IsEnabled for u64

Source§

impl IsEnabled for usize

Source§

impl IsEnabled for Wrapping<i8>

Source§

impl IsEnabled for Wrapping<i16>

Source§

impl IsEnabled for Wrapping<i32>

Source§

impl IsEnabled for Wrapping<i64>

Source§

impl IsEnabled for Wrapping<isize>

Source§

impl IsEnabled for Wrapping<u8>

Source§

impl IsEnabled for Wrapping<u16>

Source§

impl IsEnabled for Wrapping<u32>

Source§

impl IsEnabled for Wrapping<u64>

Source§

impl IsEnabled for Wrapping<usize>

Source§

impl IsEnabled for NonZeroI8

Source§

impl IsEnabled for NonZeroI16

Source§

impl IsEnabled for NonZeroI32

Source§

impl IsEnabled for NonZeroI64

Source§

impl IsEnabled for NonZeroIsize

Source§

impl IsEnabled for NonZeroU8

Source§

impl IsEnabled for NonZeroU16

Source§

impl IsEnabled for NonZeroU32

Source§

impl IsEnabled for NonZeroU64

Source§

impl IsEnabled for NonZeroUsize

Implementors§