Bug 1608150 [wpt PR 21112] - Add missing space in `./wpt lint` command line docs...
[gecko.git] / third_party / rust / indexmap / src / equivalent.rs
blobd72b2ef3a202ceb71e9d8866aafcb893869baaa9
2 use std::borrow::Borrow;
4 /// Key equivalence trait.
5 ///
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.
10 ///
11 /// # Contract
12 ///
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
20     where Q: Eq,
21           K: Borrow<Q>,
23     #[inline]
24     fn equivalent(&self, key: &K) -> bool {
25         *self == *key.borrow()
26     }