Skip to main content

## HashStable

# Trait HashStable

Source

    pub trait HashStable<CTX> {
        // Required method
        fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher);
    }

Expand description

Something that implements `HashStable<CTX>` can be hashed in a way that is stable across multiple compilation sessions.

Note that `HashStable` imposes rather more strict requirements than usual hash functions:

- Stable hashes are sometimes used as identifiers. Therefore they must conform to the corresponding `PartialEq` implementations:

  - `x == y` implies `hash_stable(x) == hash_stable(y)`, and
  - `x != y` implies `hash_stable(x) != hash_stable(y)`.

  That second condition is usually not required for hash functions (e.g. `Hash`). In practice this means that `hash_stable` must feed any information into the hasher that a `PartialEq` comparison takes into account. See #49300 for an example where violating this invariant has caused trouble in the past.

- `hash_stable()` must be independent of the current compilation session. E.g. they must not hash memory addresses or other things that are “randomly” assigned per compilation session.

- `hash_stable()` must be independent of the host architecture. The `StableHasher` takes care of endianness and `isize`/`usize` platform differences.

## Required Methods§

Source

#### fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher)

## Implementations on Foreign Types§

Source§

### impl<K, V, HCX> !HashStable<HCX> for HashMap<K, V>

Source§

### impl<V, HCX> !HashStable<HCX> for HashSet<V>

Source§

### impl<'a, T, CTX> HashStable<CTX> for &'a T
where T: HashStable<CTX> + ?Sized,

Source§

#### fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher)

Source§

### impl<A, const N: usize, CTX> HashStable<CTX> for SmallVec<[A; N]>
where A: HashStable<CTX>,

Source§

#### fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher)

Source§

### impl<CTX> HashStable<CTX> for Ordering

Source§

#### fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher)

Source§

### impl<CTX> HashStable<CTX> for bool

Source§

#### fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher)

Source§

### impl<CTX> HashStable<CTX> for char

Source§

#### fn hash_stable(&self, _: &mut CTX, hasher: &mut StableHasher)

Source§

### impl<CTX> HashStable<CTX> for f32

Source§

#### fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher)

Source§

### impl<CTX> HashStable<CTX> for f64

Source§

#### fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher)

Source§

### impl<CTX> HashStable<CTX> for i8

Source§

#### fn hash_stable(&self, _: &mut CTX, hasher: &mut StableHasher)

Source§

### impl<CTX> HashStable<CTX> for i16

Source§

#### fn hash_stable(&self, _: &mut CTX, hasher: &mut StableHasher)

Source§

### impl<CTX> HashStable<CTX> for i32

Source§

#### fn hash_stable(&self, _: &mut CTX, hasher: &mut StableHasher)

Source§

### impl<CTX> HashStable<CTX> for i64

Source§

#### fn hash_stable(&self, _: &mut CTX, hasher: &mut StableHasher)

Source§

### impl<CTX> HashStable<CTX> for i128

Source§

#### fn hash_stable(&self, _: &mut CTX, hasher: &mut StableHasher)

Source§

### impl<CTX> HashStable<CTX> for isize

Source§

#### fn hash_stable(&self, _: &mut CTX, hasher: &mut StableHasher)

Source§

### impl<CTX> HashStable<CTX> for !

Source§

#### fn hash_stable(&self, _ctx: &mut CTX, _hasher: &mut StableHasher)

Source§

### impl<CTX> HashStable<CTX> for str

Source§

#### fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher)

Source§

### impl<CTX> HashStable<CTX> for u8

Source§

#### fn hash_stable(&self, _: &mut CTX, hasher: &mut StableHasher)

Source§

### impl<CTX> HashStable<CTX> for u16

Source§

#### fn hash_stable(&self, _: &mut CTX, hasher: &mut StableHasher)

Source§

### impl<CTX> HashStable<CTX> for u32

Source§

#### fn hash_stable(&self, _: &mut CTX, hasher: &mut StableHasher)

Source§

### impl<CTX> HashStable<CTX> for u64

Source§

#### fn hash_stable(&self, _: &mut CTX, hasher: &mut StableHasher)

Source§

### impl<CTX> HashStable<CTX> for u128

Source§

#### fn hash_stable(&self, _: &mut CTX, hasher: &mut StableHasher)

Source§

### impl<CTX> HashStable<CTX> for ()

Source§

#### fn hash_stable(&self, _: &mut CTX, hasher: &mut StableHasher)

Source§

### impl<CTX> HashStable<CTX> for usize

Source§

#### fn hash_stable(&self, _: &mut CTX, hasher: &mut StableHasher)

Source§

### impl<CTX> HashStable<CTX> for Hash64

Source§

#### fn hash_stable(&self, _: &mut CTX, hasher: &mut StableHasher)

Source§

### impl<CTX> HashStable<CTX> for Hash128

Source§

#### fn hash_stable(&self, _: &mut CTX, hasher: &mut StableHasher)

Source§

### impl<CTX> HashStable<CTX> for String

Source§

#### fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher)

Source§

### impl<CTX> HashStable<CTX> for NonZero<u32>

Source§

#### fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher)

Source§

### impl<CTX> HashStable<CTX> for NonZero<usize>

Source§

#### fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher)

Source§

### impl<CTX> HashStable<CTX> for OsStr

Source§

#### fn hash_stable(&self, _: &mut CTX, hasher: &mut StableHasher)

Source§

### impl<CTX> HashStable<CTX> for Path

Source§

#### fn hash_stable(&self, _: &mut CTX, hasher: &mut StableHasher)

Source§

### impl<CTX> HashStable<CTX> for PathBuf

Source§

#### fn hash_stable(&self, _: &mut CTX, hasher: &mut StableHasher)

Source§

### impl<CTX> HashStable<CTX> for [u8]

Source§

#### fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher)

Source§

### impl<CTX, T> HashStable<CTX> for PhantomData<T>

Source§

#### fn hash_stable(&self, _ctx: &mut CTX, _hasher: &mut StableHasher)

Source§

### impl<I: Idx, CTX> HashStable<CTX> for DenseBitSet<I>

Source§

#### fn hash_stable(&self, _ctx: &mut CTX, hasher: &mut StableHasher)

Source§

### impl<I: Idx, T, CTX> HashStable<CTX> for IndexSlice<I, T>
where T: HashStable<CTX>,

Source§

#### fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher)

Source§

### impl<I: Idx, T, CTX> HashStable<CTX> for IndexVec<I, T>
where T: HashStable<CTX>,

Source§

#### fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher)

Source§

### impl<K, HCX> HashStable<HCX> for BTreeSet<K>
where K: HashStable<HCX> + StableOrd,

Source§

#### fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher)

Source§

### impl<K, R, CTX> HashStable<CTX> for IndexSet<K, R>
where K: HashStable<CTX> + Eq + Hash, R: BuildHasher,

Source§

#### fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher)

Source§

### impl<K, V, HCX> HashStable<HCX> for BTreeMap<K, V>
where K: HashStable<HCX> + StableOrd, V: HashStable<HCX>,

Source§

#### fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher)

Source§

### impl<K, V, R, CTX> HashStable<CTX> for IndexMap<K, V, R>
where K: HashStable<CTX> + Eq + Hash, V: HashStable<CTX>, R: BuildHasher,

Source§

#### fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher)

Source§

### impl<R: Idx, C: Idx, CTX> HashStable<CTX> for BitMatrix<R, C>

Source§

#### fn hash_stable(&self, _ctx: &mut CTX, hasher: &mut StableHasher)

Source§

### impl<T1, T2, CTX> HashStable<CTX> for Result<T1, T2>
where T1: HashStable<CTX>, T2: HashStable<CTX>,

Source§

#### fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher)

Source§

### impl<T1, T2, T3, CTX> HashStable<CTX> for (T1, T2, T3)
where T1: HashStable<CTX>, T2: HashStable<CTX>, T3: HashStable<CTX>,

Source§

#### fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher)

Source§

### impl<T1, T2, T3, T4, CTX> HashStable<CTX> for (T1, T2, T3, T4)
where T1: HashStable<CTX>, T2: HashStable<CTX>, T3: HashStable<CTX>, T4: HashStable<CTX>,

Source§

#### fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher)

Source§

### impl<T1: HashStable<CTX>, CTX> HashStable<CTX> for (T1,)

Source§

#### fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher)

Source§

### impl<T1: HashStable<CTX>, T2: HashStable<CTX>, CTX> HashStable<CTX> for (T1, T2)

Source§

#### fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher)

Source§

### impl<T, CTX> HashStable<CTX> for Option<T>
where T: HashStable<CTX>,

Source§

#### fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher)

Source§

### impl<T, CTX> HashStable<CTX> for Discriminant<T>

Source§

#### fn hash_stable(&self, _: &mut CTX, hasher: &mut StableHasher)

Source§

### impl<T, CTX> HashStable<CTX> for RangeInclusive<T>
where T: HashStable<CTX>,

Source§

#### fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher)

Source§

### impl<T: HashStable<CTX>, CTX> HashStable<CTX> for [T]

Source§

#### default fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher)

Source§

### impl<T: HashStable<CTX>, CTX> HashStable<CTX> for Vec<T>

Source§

#### fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher)

Source§

### impl<T: ?Sized + HashStable<CTX>, CTX> HashStable<CTX> for Box<T>

Source§

#### fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher)

Source§

### impl<T: ?Sized + HashStable<CTX>, CTX> HashStable<CTX> for Rc<T>

Source§

#### fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher)

Source§

### impl<T: ?Sized + HashStable<CTX>, CTX> HashStable<CTX> for Arc<T>

Source§

#### fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher)

## Implementors§

Source§

### impl<'a, P, T, HCX> HashStable<HCX> for TaggedRef<'a, P, T>
where P: HashStable<HCX> + Aligned + ?Sized, T: Tag + HashStable<HCX>,

Source§

### impl<CTX> HashStable<CTX> for Fingerprint

Source§

### impl<CTX> HashStable<CTX> for Pu128

Source§

### impl<CTX, T: HashStable<CTX>> HashStable<CTX> for Steal<T>

Source§

### impl<HCX, K: Hash + Eq + HashStable<HCX>, V: HashStable<HCX>> HashStable<HCX> for UnordMap<K, V>

Source§

### impl<HCX, V: Hash + Eq + HashStable<HCX>> HashStable<HCX> for UnordBag<V>

Source§

### impl<HCX, V: Hash + Eq + HashStable<HCX>> HashStable<HCX> for UnordSet<V>

Source§

### impl<I: Idx, K, V, __CTX> HashStable<__CTX> for SortedIndexMultiMap<I, K, V>
where IndexVec<I, (K, V)>: HashStable<__CTX>, Vec<I>: HashStable<__CTX>,

Source§

### impl<K: HashStable<CTX> + StableOrd, V: HashStable<CTX>, CTX> HashStable<CTX> for SortedMap<K, V>

Source§

### impl<T, CTX> HashStable<CTX> for Interned<'_, T>
where T: HashStable<CTX>,

Source§

### impl<__CTX> HashStable<__CTX> for Svh