-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Open
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCS-tracking-unimplementedStatus: The feature has not been implemented.Status: The feature has not been implemented.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Description
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.)
- Implementation: introduce the Comparable trait for BTree operations #144506
- Final comment period (FCP)1
- Stabilization PR
Unresolved Questions
- Should we use
K: Comparable<Q>
orQ: Comparable<K>
. FlipK
andQ
indexmap-rs/equivalent#5
Footnotes
Metadata
Metadata
Assignees
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCS-tracking-unimplementedStatus: The feature has not been implemented.Status: The feature has not been implemented.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.