pub trait KeyComparator<T, K>{
// 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§
Sourcefn extract_key(value: &T) -> &K
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§
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.