metrics_util

Trait 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.

Required Associated Types§

source

type Hasher: Hasher + Default

The hasher implementation used internally.

Provided Methods§

source

fn hashable(&self) -> u64

Generate the hash of this object.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl Hashable for Key

Implementors§