Feature gate: #![feature(comparable_trait)]
This is a tracking issue for adding the Comparable trait to core, to be used by BTreeMap.
See the https://docs.rs/equivalent/latest/equivalent/ trait.
The Equivalent and Comparable traits allow for more generalised accessors for BTreeMap or HashMap than what Borrow + Ord/Borrow + Eq can allow today.
Public API
// core::cmp
pub(crate) trait Equivalent<Q: ?Sized> {
fn equivalent(&self, key: &Q) -> bool;
}
impl<K: ?Sized, Q: ?Sized> Equivalent<Q> for K
where
K: Borrow<Q>,
Q: Eq,
{
}
pub(crate) trait Comparable<Q: ?Sized>: Equivalent<Q> {
fn compare(&self, key: &Q) -> Ordering;
}
impl<K: ?Sized, Q: ?Sized> Comparable<Q> for K
where
K: Borrow<Q>,
Q: Ord,
{
}
// alloc::collections::btree
impl<K, V> BTreeMap<K, V> {
fn get<Q>(&self, key: &Q) -> Option<&V>
where
Q: ?Sized,
K: Comparable<Q>;
}
Steps / History
(Remember to update the S-tracking-* label when checking boxes.)
Unresolved Questions
Feature gate:
#![feature(comparable_trait)]This is a tracking issue for adding the
Comparabletrait to core, to be used byBTreeMap.See the https://docs.rs/equivalent/latest/equivalent/ trait.
The
EquivalentandComparabletraits allow for more generalised accessors forBTreeMaporHashMapthan whatBorrow + Ord/Borrow + Eqcan allow today.Public API
Steps / History
(Remember to update the
S-tracking-*label when checking boxes.)Unresolved Questions
K: Comparable<Q>orQ: Comparable<K>. FlipKandQindexmap-rs/equivalent#5Footnotes
https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html ↩