Skip to main content

HashStable

Trait HashStable 

Source
pub trait HashStable {
    // Required method
    fn hash_stable<Hcx: HashStableContext>(
        &self,
        hcx: &mut Hcx,
        hasher: &mut StableHasher,
    );
}
Expand description

Something that implements HashStable 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<Hcx: HashStableContext>( &self, hcx: &mut Hcx, hasher: &mut StableHasher, )

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

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

Source§

impl<V> !HashStable for HashSet<V>

Source§

impl HashStable for Ordering

Source§

fn hash_stable<Hcx: HashStableContext>( &self, hcx: &mut Hcx, hasher: &mut StableHasher, )

Source§

impl HashStable for bool

Source§

fn hash_stable<Hcx: HashStableContext>( &self, hcx: &mut Hcx, hasher: &mut StableHasher, )

Source§

impl HashStable for char

Source§

fn hash_stable<Hcx>(&self, _: &mut Hcx, hasher: &mut StableHasher)

Source§

impl HashStable for f32

Source§

fn hash_stable<Hcx: HashStableContext>( &self, hcx: &mut Hcx, hasher: &mut StableHasher, )

Source§

impl HashStable for f64

Source§

fn hash_stable<Hcx: HashStableContext>( &self, hcx: &mut Hcx, hasher: &mut StableHasher, )

Source§

impl HashStable for i8

Source§

fn hash_stable<Hcx>(&self, _: &mut Hcx, hasher: &mut StableHasher)

Source§

impl HashStable for i16

Source§

fn hash_stable<Hcx>(&self, _: &mut Hcx, hasher: &mut StableHasher)

Source§

impl HashStable for i32

Source§

fn hash_stable<Hcx>(&self, _: &mut Hcx, hasher: &mut StableHasher)

Source§

impl HashStable for i64

Source§

fn hash_stable<Hcx>(&self, _: &mut Hcx, hasher: &mut StableHasher)

Source§

impl HashStable for i128

Source§

fn hash_stable<Hcx>(&self, _: &mut Hcx, hasher: &mut StableHasher)

Source§

impl HashStable for isize

Source§

fn hash_stable<Hcx>(&self, _: &mut Hcx, hasher: &mut StableHasher)

Source§

impl HashStable for !

Source§

fn hash_stable<Hcx>(&self, _hcx: &mut Hcx, _hasher: &mut StableHasher)

Source§

impl HashStable for str

Source§

fn hash_stable<Hcx: HashStableContext>( &self, hcx: &mut Hcx, hasher: &mut StableHasher, )

Source§

impl HashStable for u8

Source§

fn hash_stable<Hcx>(&self, _: &mut Hcx, hasher: &mut StableHasher)

Source§

impl HashStable for u16

Source§

fn hash_stable<Hcx>(&self, _: &mut Hcx, hasher: &mut StableHasher)

Source§

impl HashStable for u32

Source§

fn hash_stable<Hcx>(&self, _: &mut Hcx, hasher: &mut StableHasher)

Source§

impl HashStable for u64

Source§

fn hash_stable<Hcx>(&self, _: &mut Hcx, hasher: &mut StableHasher)

Source§

impl HashStable for u128

Source§

fn hash_stable<Hcx>(&self, _: &mut Hcx, hasher: &mut StableHasher)

Source§

impl HashStable for ()

Source§

fn hash_stable<Hcx>(&self, _: &mut Hcx, hasher: &mut StableHasher)

Source§

impl HashStable for usize

Source§

fn hash_stable<Hcx>(&self, _: &mut Hcx, hasher: &mut StableHasher)

Source§

impl HashStable for String

Source§

fn hash_stable<Hcx: HashStableContext>( &self, hcx: &mut Hcx, hasher: &mut StableHasher, )

Source§

impl HashStable for NonZero<u32>

Source§

fn hash_stable<Hcx: HashStableContext>( &self, hcx: &mut Hcx, hasher: &mut StableHasher, )

Source§

impl HashStable for NonZero<usize>

Source§

fn hash_stable<Hcx: HashStableContext>( &self, hcx: &mut Hcx, hasher: &mut StableHasher, )

Source§

impl HashStable for OsStr

Source§

fn hash_stable<Hcx>(&self, _: &mut Hcx, hasher: &mut StableHasher)

Source§

impl HashStable for Path

Source§

fn hash_stable<Hcx>(&self, _: &mut Hcx, hasher: &mut StableHasher)

Source§

impl HashStable for PathBuf

Source§

fn hash_stable<Hcx>(&self, _: &mut Hcx, hasher: &mut StableHasher)

Source§

impl HashStable for Hash64

Source§

fn hash_stable<Hcx>(&self, _: &mut Hcx, hasher: &mut StableHasher)

Source§

impl HashStable for Hash128

Source§

fn hash_stable<Hcx>(&self, _: &mut Hcx, hasher: &mut StableHasher)

Source§

impl HashStable for [u8]

Source§

fn hash_stable<Hcx: HashStableContext>( &self, hcx: &mut Hcx, hasher: &mut StableHasher, )

Source§

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

Source§

fn hash_stable<Hcx: HashStableContext>( &self, hcx: &mut Hcx, hasher: &mut StableHasher, )

Source§

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

Source§

fn hash_stable<Hcx: HashStableContext>( &self, hcx: &mut Hcx, hasher: &mut StableHasher, )

Source§

impl<I: Idx> HashStable for DenseBitSet<I>

Source§

fn hash_stable<Hcx: HashStableContext>( &self, _hcx: &mut Hcx, hasher: &mut StableHasher, )

Source§

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

Source§

fn hash_stable<Hcx: HashStableContext>( &self, hcx: &mut Hcx, hasher: &mut StableHasher, )

Source§

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

Source§

fn hash_stable<Hcx: HashStableContext>( &self, hcx: &mut Hcx, hasher: &mut StableHasher, )

Source§

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

Source§

fn hash_stable<Hcx: HashStableContext>( &self, hcx: &mut Hcx, hasher: &mut StableHasher, )

Source§

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

Source§

fn hash_stable<Hcx: HashStableContext>( &self, hcx: &mut Hcx, hasher: &mut StableHasher, )

Source§

impl<K, V> HashStable for BTreeMap<K, V>

Source§

fn hash_stable<Hcx: HashStableContext>( &self, hcx: &mut Hcx, hasher: &mut StableHasher, )

Source§

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

Source§

fn hash_stable<Hcx: HashStableContext>( &self, hcx: &mut Hcx, hasher: &mut StableHasher, )

Source§

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

Source§

fn hash_stable<Hcx: HashStableContext>( &self, _hcx: &mut Hcx, hasher: &mut StableHasher, )

Source§

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

Source§

fn hash_stable<Hcx: HashStableContext>( &self, hcx: &mut Hcx, hasher: &mut StableHasher, )

Source§

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

Source§

fn hash_stable<Hcx: HashStableContext>( &self, hcx: &mut Hcx, hasher: &mut StableHasher, )

Source§

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

Source§

fn hash_stable<Hcx: HashStableContext>( &self, hcx: &mut Hcx, hasher: &mut StableHasher, )

Source§

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

Source§

fn hash_stable<Hcx: HashStableContext>( &self, hcx: &mut Hcx, hasher: &mut StableHasher, )

Source§

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

Source§

fn hash_stable<Hcx: HashStableContext>( &self, hcx: &mut Hcx, hasher: &mut StableHasher, )

Source§

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

Source§

fn hash_stable<Hcx: HashStableContext>( &self, hcx: &mut Hcx, hasher: &mut StableHasher, )

Source§

impl<T> HashStable for PhantomData<T>

Source§

fn hash_stable<Hcx>(&self, _hcx: &mut Hcx, _hasher: &mut StableHasher)

Source§

impl<T> HashStable for Discriminant<T>

Source§

fn hash_stable<Hcx: HashStableContext>( &self, _: &mut Hcx, hasher: &mut StableHasher, )

Source§

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

Source§

fn hash_stable<Hcx: HashStableContext>( &self, hcx: &mut Hcx, hasher: &mut StableHasher, )

Source§

impl<T: HashStable> HashStable for [T]

Source§

default fn hash_stable<Hcx: HashStableContext>( &self, hcx: &mut Hcx, hasher: &mut StableHasher, )

Source§

impl<T: HashStable> HashStable for Vec<T>

Source§

fn hash_stable<Hcx: HashStableContext>( &self, hcx: &mut Hcx, hasher: &mut StableHasher, )

Source§

impl<T: ?Sized + HashStable> HashStable for Box<T>

Source§

fn hash_stable<Hcx: HashStableContext>( &self, hcx: &mut Hcx, hasher: &mut StableHasher, )

Source§

impl<T: ?Sized + HashStable> HashStable for Rc<T>

Source§

fn hash_stable<Hcx: HashStableContext>( &self, hcx: &mut Hcx, hasher: &mut StableHasher, )

Source§

impl<T: ?Sized + HashStable> HashStable for Arc<T>

Source§

fn hash_stable<Hcx: HashStableContext>( &self, hcx: &mut Hcx, hasher: &mut StableHasher, )

Implementors§