Trait hashindexed::KeyComparator
[−]
[src]
pub trait KeyComparator<T, K> where K: Eq + Hash { fn extract_key(value: &T) -> &K; fn key_eq(u: &T, v: &T) -> bool { ... } fn key_hash<H: Hasher>(value: &T, state: &mut H) { ... } }
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
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
fn key_eq(u: &T, v: &T) -> bool
Test equality of keys extracted from given values u, v.
fn key_hash<H: Hasher>(value: &T, state: &mut H)
Generate a hash of a key retrieved from a given value.