hashindexed

Trait KeyComparator

Source
pub trait KeyComparator<T, K>
where K: Eq + Hash,
{ // Required method fn extract_key(value: &T) -> &K; // Provided methods fn key_eq(u: &T, v: &T) -> bool { ... } fn key_hash<H: Hasher>(value: &T, state: &mut H) { ... } }
Expand description

Configures how values are indexd.

User should either implement extract_key() or implement key_eq() and key_hash() (in the latter case, extract_key() technically needs an implementation but will never be used, so it can simply panic).

Note that contains(), get(), replace() and remove() require implementation of extract_key() in order to function correctly!

Required Methods§

Source

fn extract_key(value: &T) -> &K

This function should return a key extracted from the value. eq and hash are implemented on this key.

Note that the implementation could simply panic if key_eq() and key_hash() are implemented instead; however some functions will not work in this case.

Provided Methods§

Source

fn key_eq(u: &T, v: &T) -> bool

Test equality of keys extracted from given values u, v.

Source

fn key_hash<H: Hasher>(value: &T, state: &mut H)

Generate a hash of a key retrieved from a given value.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§