1 | /// Trait used to retrieve the weight of a key-value pair. |
---|---|
2 | pub trait WeightScale<K, V> { |
3 | /// Returns the weight of a key-value pair. |
4 | fn weight(&self, key: &K, value: &V) -> usize; |
5 | } |
6 | |
7 | /// A scale that always return 0. |
8 | #[derive(Clone, Copy, Debug, Default)] |
9 | pub struct ZeroWeightScale; |
10 | |
11 | impl<K, V> WeightScale<K, V> for ZeroWeightScale { |
12 | #[inline] |
13 | fn weight(&self, _: &K, _: &V) -> usize { |
14 | 0 |
15 | } |
16 | } |
17 |