Skip to content

Commit 38aeaa0

Browse files
committed
more to core under feature flag
1 parent 20329c3 commit 38aeaa0

File tree

6 files changed

+51
-56
lines changed

6 files changed

+51
-56
lines changed

library/alloc/src/collections/btree/cmp.rs

Lines changed: 0 additions & 52 deletions
This file was deleted.

library/alloc/src/collections/btree/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
mod append;
22
mod borrow;
3-
mod cmp;
43
mod dedup_sorted_iter;
54
mod fix;
65
pub(super) mod map;

library/alloc/src/collections/btree/navigate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
use core::cmp::Comparable;
12
use core::ops::RangeBounds;
23
use core::{hint, ptr};
34

4-
use super::cmp::Comparable;
55
use super::node::ForceResult::*;
66
use super::node::{Handle, NodeRef, marker};
77
use super::search::SearchBound;

library/alloc/src/collections/btree/search.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
use core::cmp::Ordering;
1+
use core::cmp::{Comparable, Ordering};
22
use core::ops::{Bound, RangeBounds};
33

44
use SearchBound::*;
55
use SearchResult::*;
66

7-
use super::cmp::Comparable;
87
use super::node::ForceResult::*;
98
use super::node::{Handle, NodeRef, marker};
109

library/alloc/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
#![feature(char_max_len)]
108108
#![feature(clone_to_uninit)]
109109
#![feature(coerce_unsized)]
110+
#![feature(comparable_trait)]
110111
#![feature(const_default)]
111112
#![feature(const_eval_select)]
112113
#![feature(const_heap)]

library/core/src/cmp.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,6 +1510,54 @@ pub macro PartialOrd($item:item) {
15101510
/* compiler built-in */
15111511
}
15121512

1513+
/// Key equivalence trait.
1514+
///
1515+
/// This trait allows hash table lookup to be customized.
1516+
///
1517+
/// # Contract
1518+
///
1519+
/// The implementor **must** hash like `Q`, if it is hashable.
1520+
#[unstable(feature = "comparable_trait", issue = "145986")]
1521+
pub trait Equivalent<Q: ?Sized> {
1522+
/// Compare self to `key` and return `true` if they are equal.
1523+
#[unstable(feature = "comparable_trait", issue = "145986")]
1524+
fn equivalent(&self, key: &Q) -> bool;
1525+
}
1526+
1527+
#[unstable(feature = "comparable_trait", issue = "145986")]
1528+
impl<K: ?Sized, Q: ?Sized> Equivalent<Q> for K
1529+
where
1530+
K: crate::borrow::Borrow<Q>,
1531+
Q: Eq,
1532+
{
1533+
#[inline]
1534+
fn equivalent(&self, key: &Q) -> bool {
1535+
PartialEq::eq(self.borrow(), key)
1536+
}
1537+
}
1538+
1539+
/// Key ordering trait.
1540+
///
1541+
/// This trait allows ordered map lookup to be customized.
1542+
#[unstable(feature = "comparable_trait", issue = "145986")]
1543+
pub trait Comparable<Q: ?Sized>: Equivalent<Q> {
1544+
/// Compare self to `key` and return their ordering.
1545+
#[unstable(feature = "comparable_trait", issue = "145986")]
1546+
fn compare(&self, key: &Q) -> Ordering;
1547+
}
1548+
1549+
#[unstable(feature = "comparable_trait", issue = "145986")]
1550+
impl<K: ?Sized, Q: ?Sized> Comparable<Q> for K
1551+
where
1552+
K: crate::borrow::Borrow<Q>,
1553+
Q: Ord,
1554+
{
1555+
#[inline]
1556+
fn compare(&self, key: &Q) -> Ordering {
1557+
Ord::cmp(self.borrow(), key)
1558+
}
1559+
}
1560+
15131561
/// Compares and returns the minimum of two values.
15141562
///
15151563
/// Returns the first argument if the comparison determines them to be equal.

0 commit comments

Comments
 (0)