Trait metrics_util::Hashable
source · pub trait Hashable: Hash {
type Hasher: Hasher + Default;
// Provided method
fn hashable(&self) -> u64 { ... }
}
Expand description
A type that can hash itself.
In high-performance use cases, an object can pre-hash itself, or memoize its hash value, when it
is anticipated that an object will be hashed multiple times. Rather than the standard library
Hash
trait, Hashable
exposes an interface that forces objects to hash themselves entirely,
providing only the resulting 8-byte hash.
As a key may sometimes need to be rehashed, we need to ensure that the same hashing algorithm
used to pre-generate the hash for this value is used when rehashing it. All implementors must
define the hashing algorithm used by specifying the Hasher
associated type.
A default implementation, DefaultHashable
, is provided that utilizes the same hashing
algorithm that Key
uses, which is high-performance. This type can be used to
satisfy Hashable
so long as the type itself is already Hash
.