2 use std::borrow::Borrow;
4 /// Key equivalence trait.
6 /// This trait allows hash table lookup to be customized.
7 /// It has one blanket implementation that uses the regular `Borrow` solution,
8 /// just like `HashMap` and `BTreeMap` do, so that you can pass `&str` to lookup
9 /// into a map with `String` keys and so on.
13 /// The implementor **must** hash like `K`, if it is hashable.
14 pub trait Equivalent<K: ?Sized> {
15 /// Compare self to `key` and return `true` if they are equal.
16 fn equivalent(&self, key: &K) -> bool;
19 impl<Q: ?Sized, K: ?Sized> Equivalent<K> for Q
24 fn equivalent(&self, key: &K) -> bool {
25 *self == *key.borrow()