pub trait StableHash {
// Required method
fn stable_hash<H>(&self, state: &mut H)
where H: StableHasher + ?Sized;
}Expand description
A trait for types that can be hashed in a stable manner.
The trait provides a single method that takes a mutable reference to a
StableHasher and feeds the type’s data into the hasher.
§Example
ⓘ
#[derive(Debug)]
struct Point {
x: i32,
y: i32,
}
impl StableHash for Point {
fn stable_hash<H: StableHasher + ?Sized>(&self, state: &mut H) {
self.x.stable_hash(state);
self.y.stable_hash(state);
}
}
let point = Point { x: 10, y: 20 };
let mut hasher = StableSipHasher::new();
point.stable_hash(&mut hasher);
let hash = hasher.finish();Required Methods§
Sourcefn stable_hash<H>(&self, state: &mut H)where
H: StableHasher + ?Sized,
fn stable_hash<H>(&self, state: &mut H)where
H: StableHasher + ?Sized,
Feeds this type’s data into the provided hasher.
Implementations should hash all fields that contribute to the type’s identity in a consistent order. The hash should be stable across different program runs and platforms.
§Arguments
state- The hasher to feed data into
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.