pub trait AsKeys {
// Required method
fn as_keys(&self) -> Vec<u64>;
}Expand description
Trait for anything that can be turned into a key
The reason this exists is to allow for prefix invalidation, so lists or
tuples should return one hash per element.
It’s automatically implemented for String, str and any tuple of size
2 - 12 where each element implements Hash.
If your keys aren’t covered by the default implementation for some reason,
you can implement this manually.
§Example
struct MyType {
item1: String,
item2: String,
}
impl AsKey for MyType {
fn as_key(&self) -> Vec<u64> {
let mut hash = FnvHasher::default();
self.item1.hash(&mut hash);
let hash1 = hash.finish();
hash = FnvHasher::default();
self.item2.hash(&mut hash);
let hash2 = hash.finish();
vec![hash1, hash2]
}
}}