1 | //! A base trait to expose a precomputed hash for a type. |
2 | |
3 | /// A trait to expose a precomputed hash for a type. |
4 | pub trait PrecomputedHash { |
5 | // TODO(emilio): Perhaps an associated type would be on point here. |
6 | |
7 | /// Return the precomputed hash for this item. |
8 | fn precomputed_hash(&self) -> u32; |
9 | } |
10 | |
11 | // These are equivalent to the `std::Hash` impls. |
12 | impl<'a, T: PrecomputedHash> PrecomputedHash for &'a T { |
13 | fn precomputed_hash(&self) -> u32 { |
14 | (**self).precomputed_hash() |
15 | } |
16 | } |
17 | |
18 | impl<'a, T: PrecomputedHash> PrecomputedHash for &'a mut T { |
19 | fn precomputed_hash(&self) -> u32 { |
20 | (**self).precomputed_hash() |
21 | } |
22 | } |
23 | |