Trait core::hash::Hash 1.0.0
[−]
[src]
pub trait Hash {
fn hash<H: Hasher>(&self, state: &mut H);
fn hash_slice<H: Hasher>(data: &[Self], state: &mut H)
where
Self: Sized,
{ ... }
}A hashable type.
Types implementing Hash are able to be hashed with an instance of
Hasher.
Implementing Hash
You can derive Hash with #[derive(Hash)] if all fields implement Hash.
The resulting hash will be the combination of the values from calling
hash on each field.
#[derive(Hash)] struct Rustacean { name: String, country: String, }Run
If you need more control over how a value is hashed, you can of course
implement the Hash trait yourself:
use std::hash::{Hash, Hasher}; struct Person { id: u32, name: String, phone: u64, } impl Hash for Person { fn hash<H: Hasher>(&self, state: &mut H) { self.id.hash(state); self.phone.hash(state); } }Run
Hash and Eq
When implementing both Hash and Eq, it is important that the following
property holds:
k1 == k2 -> hash(k1) == hash(k2)
In other words, if two keys are equal, their hashes must also be equal.
HashMap and HashSet both rely on this behavior.
Thankfully, you won't need to worry about upholding this property when
deriving both Eq and Hash with #[derive(PartialEq, Eq, Hash)].
Required Methods
Provided Methods
fn hash_slice<H: Hasher>(data: &[Self], state: &mut H) where
Self: Sized, 1.3.0
Self: Sized,
Implementors
impl<T: Hash> Hash for Wrapping<T>impl<T> Hash for Discriminant<T>impl<T: Hash> Hash for ManuallyDrop<T>impl<T: Hash + Zeroable> Hash for NonZero<T>impl<Ret> Hash for fn() -> Retimpl<Ret> Hash for extern "C" fn() -> Retimpl<Ret> Hash for unsafe fn() -> Retimpl<Ret> Hash for unsafe extern "C" fn() -> Retimpl<Ret, A> Hash for fn(_: A) -> Retimpl<Ret, A> Hash for extern "C" fn(_: A) -> Retimpl<Ret, A> Hash for extern "C" fn(_: A, ...) -> Retimpl<Ret, A> Hash for unsafe fn(_: A) -> Retimpl<Ret, A> Hash for unsafe extern "C" fn(_: A) -> Retimpl<Ret, A> Hash for unsafe extern "C" fn(_: A, ...) -> Retimpl<Ret, A, B> Hash for fn(_: A, _: B) -> Retimpl<Ret, A, B> Hash for extern "C" fn(_: A, _: B) -> Retimpl<Ret, A, B> Hash for extern "C" fn(_: A, _: B, ...) -> Retimpl<Ret, A, B> Hash for unsafe fn(_: A, _: B) -> Retimpl<Ret, A, B> Hash for unsafe extern "C" fn(_: A, _: B) -> Retimpl<Ret, A, B> Hash for unsafe extern "C" fn(_: A, _: B, ...) -> Retimpl<Ret, A, B, C> Hash for fn(_: A, _: B, _: C) -> Retimpl<Ret, A, B, C> Hash for extern "C" fn(_: A, _: B, _: C) -> Retimpl<Ret, A, B, C> Hash for extern "C" fn(_: A, _: B, _: C, ...) -> Retimpl<Ret, A, B, C> Hash for unsafe fn(_: A, _: B, _: C) -> Retimpl<Ret, A, B, C> Hash for unsafe extern "C" fn(_: A, _: B, _: C) -> Retimpl<Ret, A, B, C> Hash for unsafe extern "C" fn(_: A, _: B, _: C, ...) -> Retimpl<Ret, A, B, C, D> Hash for fn(_: A, _: B, _: C, _: D) -> Retimpl<Ret, A, B, C, D> Hash for extern "C" fn(_: A, _: B, _: C, _: D) -> Retimpl<Ret, A, B, C, D> Hash for extern "C" fn(_: A, _: B, _: C, _: D, ...) -> Retimpl<Ret, A, B, C, D> Hash for unsafe fn(_: A, _: B, _: C, _: D) -> Retimpl<Ret, A, B, C, D> Hash for unsafe extern "C" fn(_: A, _: B, _: C, _: D) -> Retimpl<Ret, A, B, C, D> Hash for unsafe extern "C" fn(_: A, _: B, _: C, _: D, ...) -> Retimpl<Ret, A, B, C, D, E> Hash for fn(_: A, _: B, _: C, _: D, _: E) -> Retimpl<Ret, A, B, C, D, E> Hash for extern "C" fn(_: A, _: B, _: C, _: D, _: E) -> Retimpl<Ret, A, B, C, D, E> Hash for extern "C" fn(_: A, _: B, _: C, _: D, _: E, ...) -> Retimpl<Ret, A, B, C, D, E> Hash for unsafe fn(_: A, _: B, _: C, _: D, _: E) -> Retimpl<Ret, A, B, C, D, E> Hash for unsafe extern "C" fn(_: A, _: B, _: C, _: D, _: E) -> Retimpl<Ret, A, B, C, D, E> Hash for unsafe extern "C" fn(_: A, _: B, _: C, _: D, _: E, ...) -> Retimpl<Ret, A, B, C, D, E, F> Hash for fn(_: A, _: B, _: C, _: D, _: E, _: F) -> Retimpl<Ret, A, B, C, D, E, F> Hash for extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F) -> Retimpl<Ret, A, B, C, D, E, F> Hash for extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, ...) -> Retimpl<Ret, A, B, C, D, E, F> Hash for unsafe fn(_: A, _: B, _: C, _: D, _: E, _: F) -> Retimpl<Ret, A, B, C, D, E, F> Hash for unsafe extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F) -> Retimpl<Ret, A, B, C, D, E, F> Hash for unsafe extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, ...) -> Retimpl<Ret, A, B, C, D, E, F, G> Hash for fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G) -> Retimpl<Ret, A, B, C, D, E, F, G> Hash for extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G) -> Retimpl<Ret, A, B, C, D, E, F, G> Hash for extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, ...) -> Retimpl<Ret, A, B, C, D, E, F, G> Hash for unsafe fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G) -> Retimpl<Ret, A, B, C, D, E, F, G> Hash for unsafe extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G) -> Retimpl<Ret, A, B, C, D, E, F, G> Hash for unsafe extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, ...) -> Retimpl<Ret, A, B, C, D, E, F, G, H> Hash for fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H) -> Retimpl<Ret, A, B, C, D, E, F, G, H> Hash for extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H) -> Retimpl<Ret, A, B, C, D, E, F, G, H> Hash for extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, ...) -> Retimpl<Ret, A, B, C, D, E, F, G, H> Hash for unsafe fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H) -> Retimpl<Ret, A, B, C, D, E, F, G, H> Hash for unsafe extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H) -> Retimpl<Ret, A, B, C, D, E, F, G, H> Hash for unsafe extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, ...) -> Retimpl<Ret, A, B, C, D, E, F, G, H, I> Hash for fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I) -> Retimpl<Ret, A, B, C, D, E, F, G, H, I> Hash for extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I) -> Retimpl<Ret, A, B, C, D, E, F, G, H, I> Hash for extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I, ...) -> Retimpl<Ret, A, B, C, D, E, F, G, H, I> Hash for unsafe fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I) -> Retimpl<Ret, A, B, C, D, E, F, G, H, I> Hash for unsafe extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I) -> Retimpl<Ret, A, B, C, D, E, F, G, H, I> Hash for unsafe extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I, ...) -> Retimpl<Ret, A, B, C, D, E, F, G, H, I, J> Hash for fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I, _: J) -> Retimpl<Ret, A, B, C, D, E, F, G, H, I, J> Hash for extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I, _: J) -> Retimpl<Ret, A, B, C, D, E, F, G, H, I, J> Hash for extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I, _: J, ...) -> Retimpl<Ret, A, B, C, D, E, F, G, H, I, J> Hash for unsafe fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I, _: J) -> Retimpl<Ret, A, B, C, D, E, F, G, H, I, J> Hash for unsafe extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I, _: J) -> Retimpl<Ret, A, B, C, D, E, F, G, H, I, J> Hash for unsafe extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I, _: J, ...) -> Retimpl<Ret, A, B, C, D, E, F, G, H, I, J, K> Hash for fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I, _: J, _: K) -> Retimpl<Ret, A, B, C, D, E, F, G, H, I, J, K> Hash for extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I, _: J, _: K) -> Retimpl<Ret, A, B, C, D, E, F, G, H, I, J, K> Hash for extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I, _: J, _: K, ...) -> Retimpl<Ret, A, B, C, D, E, F, G, H, I, J, K> Hash for unsafe fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I, _: J, _: K) -> Retimpl<Ret, A, B, C, D, E, F, G, H, I, J, K> Hash for unsafe extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I, _: J, _: K) -> Retimpl<Ret, A, B, C, D, E, F, G, H, I, J, K> Hash for unsafe extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I, _: J, _: K, ...) -> Retimpl<Ret, A, B, C, D, E, F, G, H, I, J, K, L> Hash for fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I, _: J, _: K, _: L) -> Retimpl<Ret, A, B, C, D, E, F, G, H, I, J, K, L> Hash for extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I, _: J, _: K, _: L) -> Retimpl<Ret, A, B, C, D, E, F, G, H, I, J, K, L> Hash for extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I, _: J, _: K, _: L, ...) -> Retimpl<Ret, A, B, C, D, E, F, G, H, I, J, K, L> Hash for unsafe fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I, _: J, _: K, _: L) -> Retimpl<Ret, A, B, C, D, E, F, G, H, I, J, K, L> Hash for unsafe extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I, _: J, _: K, _: L) -> Retimpl<Ret, A, B, C, D, E, F, G, H, I, J, K, L> Hash for unsafe extern "C" fn(_: A, _: B, _: C, _: D, _: E, _: F, _: G, _: H, _: I, _: J, _: K, _: L, ...) -> Retimpl<T: ?Sized> Hash for PhantomData<T>impl<Y: Hash, R: Hash> Hash for GeneratorState<Y, R>impl Hash for RangeFullimpl<Idx: Hash> Hash for Range<Idx>impl<Idx: Hash> Hash for RangeFrom<Idx>impl<Idx: Hash> Hash for RangeTo<Idx>impl<Idx: Hash> Hash for RangeInclusive<Idx>impl<Idx: Hash> Hash for RangeToInclusive<Idx>impl Hash for Orderingimpl Hash for Infallibleimpl Hash for TypeIdimpl<T: Hash> Hash for [T; 0]impl<T: Hash> Hash for [T; 1]impl<T: Hash> Hash for [T; 2]impl<T: Hash> Hash for [T; 3]impl<T: Hash> Hash for [T; 4]impl<T: Hash> Hash for [T; 5]impl<T: Hash> Hash for [T; 6]impl<T: Hash> Hash for [T; 7]impl<T: Hash> Hash for [T; 8]impl<T: Hash> Hash for [T; 9]impl<T: Hash> Hash for [T; 10]impl<T: Hash> Hash for [T; 11]impl<T: Hash> Hash for [T; 12]impl<T: Hash> Hash for [T; 13]impl<T: Hash> Hash for [T; 14]impl<T: Hash> Hash for [T; 15]impl<T: Hash> Hash for [T; 16]impl<T: Hash> Hash for [T; 17]impl<T: Hash> Hash for [T; 18]impl<T: Hash> Hash for [T; 19]impl<T: Hash> Hash for [T; 20]impl<T: Hash> Hash for [T; 21]impl<T: Hash> Hash for [T; 22]impl<T: Hash> Hash for [T; 23]impl<T: Hash> Hash for [T; 24]impl<T: Hash> Hash for [T; 25]impl<T: Hash> Hash for [T; 26]impl<T: Hash> Hash for [T; 27]impl<T: Hash> Hash for [T; 28]impl<T: Hash> Hash for [T; 29]impl<T: Hash> Hash for [T; 30]impl<T: Hash> Hash for [T; 31]impl<T: Hash> Hash for [T; 32]impl<T: Hash> Hash for Option<T>impl Hash for NoneErrorimpl<T: Hash, E: Hash> Hash for Result<T, E>impl Hash for u8impl Hash for u16impl Hash for u32impl Hash for u64impl Hash for usizeimpl Hash for i8impl Hash for i16impl Hash for i32impl Hash for i64impl Hash for isizeimpl Hash for u128impl Hash for i128impl Hash for boolimpl Hash for charimpl Hash for strimpl Hash for ()impl<A: Hash + ?Sized> Hash for (A,) where
A: ,impl<A: Hash, B: Hash + ?Sized> Hash for (A, B) where
B: ,impl<A: Hash, B: Hash, C: Hash + ?Sized> Hash for (A, B, C) where
C: ,impl<A: Hash, B: Hash, C: Hash, D: Hash + ?Sized> Hash for (A, B, C, D) where
D: ,impl<A: Hash, B: Hash, C: Hash, D: Hash, E: Hash + ?Sized> Hash for (A, B, C, D, E) where
E: ,impl<A: Hash, B: Hash, C: Hash, D: Hash, E: Hash, F: Hash + ?Sized> Hash for (A, B, C, D, E, F) where
F: ,impl<A: Hash, B: Hash, C: Hash, D: Hash, E: Hash, F: Hash, G: Hash + ?Sized> Hash for (A, B, C, D, E, F, G) where
G: ,impl<A: Hash, B: Hash, C: Hash, D: Hash, E: Hash, F: Hash, G: Hash, H: Hash + ?Sized> Hash for (A, B, C, D, E, F, G, H) where
H: ,impl<A: Hash, B: Hash, C: Hash, D: Hash, E: Hash, F: Hash, G: Hash, H: Hash, I: Hash + ?Sized> Hash for (A, B, C, D, E, F, G, H, I) where
I: ,impl<A: Hash, B: Hash, C: Hash, D: Hash, E: Hash, F: Hash, G: Hash, H: Hash, I: Hash, J: Hash + ?Sized> Hash for (A, B, C, D, E, F, G, H, I, J) where
J: ,impl<A: Hash, B: Hash, C: Hash, D: Hash, E: Hash, F: Hash, G: Hash, H: Hash, I: Hash, J: Hash, K: Hash + ?Sized> Hash for (A, B, C, D, E, F, G, H, I, J, K) where
K: ,impl<A: Hash, B: Hash, C: Hash, D: Hash, E: Hash, F: Hash, G: Hash, H: Hash, I: Hash, J: Hash, K: Hash, L: Hash + ?Sized> Hash for (A, B, C, D, E, F, G, H, I, J, K, L) where
L: ,impl<T: Hash> Hash for [T]impl<'a, T: ?Sized + Hash> Hash for &'a Timpl<'a, T: ?Sized + Hash> Hash for &'a mut Timpl<T: ?Sized> Hash for *const Timpl<T: ?Sized> Hash for *mut Timpl Hash for Error