To hash custom types, implement the std::hash::Hash trait for your struct and combine the hashes of its fields using a std::collections::hash_map::DefaultHasher.
use std::hash::{Hash, Hasher};
use std::collections::hash_map::DefaultHasher;
struct Point {
x: i32,
y: i32,
}
impl Hash for Point {
fn hash<H: Hasher>(&self, state: &mut H) {
self.x.hash(state);
self.y.hash(state);
}
}
This allows your Point struct to be used as a key in std::collections::HashMap.