1
Fork 0

stabilize RangeBounds collections_range #30877

rename RangeBounds::start() -> start_bound()
rename RangeBounds::end() -> end_bound()
This commit is contained in:
Cory Sherman 2018-05-24 04:39:35 -07:00
parent b4463d788b
commit 1440f300d8
7 changed files with 68 additions and 100 deletions

View file

@ -1834,7 +1834,7 @@ fn range_search<BorrowType, K, V, Q: ?Sized, R: RangeBounds<Q>>(
Handle<NodeRef<BorrowType, K, V, marker::Leaf>, marker::Edge>) Handle<NodeRef<BorrowType, K, V, marker::Leaf>, marker::Edge>)
where Q: Ord, K: Borrow<Q> where Q: Ord, K: Borrow<Q>
{ {
match (range.start(), range.end()) { match (range.start_bound(), range.end_bound()) {
(Excluded(s), Excluded(e)) if s==e => (Excluded(s), Excluded(e)) if s==e =>
panic!("range start and end are equal and excluded in BTreeMap"), panic!("range start and end are equal and excluded in BTreeMap"),
(Included(s), Included(e)) | (Included(s), Included(e)) |
@ -1852,7 +1852,7 @@ fn range_search<BorrowType, K, V, Q: ?Sized, R: RangeBounds<Q>>(
let mut diverged = false; let mut diverged = false;
loop { loop {
let min_edge = match (min_found, range.start()) { let min_edge = match (min_found, range.start_bound()) {
(false, Included(key)) => match search::search_linear(&min_node, key) { (false, Included(key)) => match search::search_linear(&min_node, key) {
(i, true) => { min_found = true; i }, (i, true) => { min_found = true; i },
(i, false) => i, (i, false) => i,
@ -1866,7 +1866,7 @@ fn range_search<BorrowType, K, V, Q: ?Sized, R: RangeBounds<Q>>(
(true, Excluded(_)) => 0, (true, Excluded(_)) => 0,
}; };
let max_edge = match (max_found, range.end()) { let max_edge = match (max_found, range.end_bound()) {
(false, Included(key)) => match search::search_linear(&max_node, key) { (false, Included(key)) => match search::search_linear(&max_node, key) {
(i, true) => { max_found = true; i+1 }, (i, true) => { max_found = true; i+1 },
(i, false) => i, (i, false) => i,

View file

@ -1493,12 +1493,12 @@ impl String {
// Because the range removal happens in Drop, if the Drain iterator is leaked, // Because the range removal happens in Drop, if the Drain iterator is leaked,
// the removal will not happen. // the removal will not happen.
let len = self.len(); let len = self.len();
let start = match range.start() { let start = match range.start_bound() {
Included(&n) => n, Included(&n) => n,
Excluded(&n) => n + 1, Excluded(&n) => n + 1,
Unbounded => 0, Unbounded => 0,
}; };
let end = match range.end() { let end = match range.end_bound() {
Included(&n) => n + 1, Included(&n) => n + 1,
Excluded(&n) => n, Excluded(&n) => n,
Unbounded => len, Unbounded => len,
@ -1551,12 +1551,12 @@ impl String {
// Replace_range does not have the memory safety issues of a vector Splice. // Replace_range does not have the memory safety issues of a vector Splice.
// of the vector version. The data is just plain bytes. // of the vector version. The data is just plain bytes.
match range.start() { match range.start_bound() {
Included(&n) => assert!(self.is_char_boundary(n)), Included(&n) => assert!(self.is_char_boundary(n)),
Excluded(&n) => assert!(self.is_char_boundary(n + 1)), Excluded(&n) => assert!(self.is_char_boundary(n + 1)),
Unbounded => {}, Unbounded => {},
}; };
match range.end() { match range.end_bound() {
Included(&n) => assert!(self.is_char_boundary(n + 1)), Included(&n) => assert!(self.is_char_boundary(n + 1)),
Excluded(&n) => assert!(self.is_char_boundary(n)), Excluded(&n) => assert!(self.is_char_boundary(n)),
Unbounded => {}, Unbounded => {},

View file

@ -1166,12 +1166,12 @@ impl<T> Vec<T> {
// the hole, and the vector length is restored to the new length. // the hole, and the vector length is restored to the new length.
// //
let len = self.len(); let len = self.len();
let start = match range.start() { let start = match range.start_bound() {
Included(&n) => n, Included(&n) => n,
Excluded(&n) => n + 1, Excluded(&n) => n + 1,
Unbounded => 0, Unbounded => 0,
}; };
let end = match range.end() { let end = match range.end_bound() {
Included(&n) => n + 1, Included(&n) => n + 1,
Excluded(&n) => n, Excluded(&n) => n,
Unbounded => len, Unbounded => len,

View file

@ -980,12 +980,12 @@ impl<T> VecDeque<T> {
// and the head/tail values will be restored correctly. // and the head/tail values will be restored correctly.
// //
let len = self.len(); let len = self.len();
let start = match range.start() { let start = match range.start_bound() {
Included(&n) => n, Included(&n) => n,
Excluded(&n) => n + 1, Excluded(&n) => n + 1,
Unbounded => 0, Unbounded => 0,
}; };
let end = match range.end() { let end = match range.end_bound() {
Included(&n) => n + 1, Included(&n) => n + 1,
Excluded(&n) => n, Excluded(&n) => n,
Unbounded => len, Unbounded => len,

View file

@ -588,14 +588,12 @@ impl<Idx: PartialOrd<Idx>> RangeToInclusive<Idx> {
/// `Bound`s are range endpoints: /// `Bound`s are range endpoints:
/// ///
/// ``` /// ```
/// #![feature(collections_range)]
///
/// use std::ops::Bound::*; /// use std::ops::Bound::*;
/// use std::ops::RangeBounds; /// use std::ops::RangeBounds;
/// ///
/// assert_eq!((..100).start(), Unbounded); /// assert_eq!((..100).start_bound(), Unbounded);
/// assert_eq!((1..12).start(), Included(&1)); /// assert_eq!((1..12).start_bound(), Included(&1));
/// assert_eq!((1..12).end(), Excluded(&12)); /// assert_eq!((1..12).end_bound(), Excluded(&12));
/// ``` /// ```
/// ///
/// Using a tuple of `Bound`s as an argument to [`BTreeMap::range`]. /// Using a tuple of `Bound`s as an argument to [`BTreeMap::range`].
@ -632,9 +630,7 @@ pub enum Bound<T> {
Unbounded, Unbounded,
} }
#[unstable(feature = "collections_range", #[stable(feature = "collections_range", since = "1.28.0")]
reason = "might be replaced with `Into<_>` and a type containing two `Bound` values",
issue = "30877")]
/// `RangeBounds` is implemented by Rust's built-in range types, produced /// `RangeBounds` is implemented by Rust's built-in range types, produced
/// by range syntax like `..`, `a..`, `..b` or `c..d`. /// by range syntax like `..`, `a..`, `..b` or `c..d`.
pub trait RangeBounds<T: ?Sized> { pub trait RangeBounds<T: ?Sized> {
@ -645,17 +641,16 @@ pub trait RangeBounds<T: ?Sized> {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// #![feature(collections_range)]
///
/// # fn main() { /// # fn main() {
/// use std::ops::Bound::*; /// use std::ops::Bound::*;
/// use std::ops::RangeBounds; /// use std::ops::RangeBounds;
/// ///
/// assert_eq!((..10).start(), Unbounded); /// assert_eq!((..10).start_bound(), Unbounded);
/// assert_eq!((3..10).start(), Included(&3)); /// assert_eq!((3..10).start_bound(), Included(&3));
/// # } /// # }
/// ``` /// ```
fn start(&self) -> Bound<&T>; #[stable(feature = "collections_range", since = "1.28.0")]
fn start_bound(&self) -> Bound<&T>;
/// End index bound. /// End index bound.
/// ///
@ -664,17 +659,16 @@ pub trait RangeBounds<T: ?Sized> {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// #![feature(collections_range)]
///
/// # fn main() { /// # fn main() {
/// use std::ops::Bound::*; /// use std::ops::Bound::*;
/// use std::ops::RangeBounds; /// use std::ops::RangeBounds;
/// ///
/// assert_eq!((3..).end(), Unbounded); /// assert_eq!((3..).end_bound(), Unbounded);
/// assert_eq!((3..10).end(), Excluded(&10)); /// assert_eq!((3..10).end_bound(), Excluded(&10));
/// # } /// # }
/// ``` /// ```
fn end(&self) -> Bound<&T>; #[stable(feature = "collections_range", since = "1.28.0")]
fn end_bound(&self) -> Bound<&T>;
/// Returns `true` if `item` is contained in the range. /// Returns `true` if `item` is contained in the range.
@ -699,13 +693,13 @@ pub trait RangeBounds<T: ?Sized> {
T: PartialOrd<U>, T: PartialOrd<U>,
U: ?Sized + PartialOrd<T>, U: ?Sized + PartialOrd<T>,
{ {
(match self.start() { (match self.start_bound() {
Included(ref start) => *start <= item, Included(ref start) => *start <= item,
Excluded(ref start) => *start < item, Excluded(ref start) => *start < item,
Unbounded => true, Unbounded => true,
}) })
&& &&
(match self.end() { (match self.end_bound() {
Included(ref end) => item <= *end, Included(ref end) => item <= *end,
Excluded(ref end) => item < *end, Excluded(ref end) => item < *end,
Unbounded => true, Unbounded => true,
@ -715,83 +709,69 @@ pub trait RangeBounds<T: ?Sized> {
use self::Bound::{Excluded, Included, Unbounded}; use self::Bound::{Excluded, Included, Unbounded};
#[unstable(feature = "collections_range", #[stable(feature = "collections_range", since = "1.28.0")]
reason = "might be replaced with `Into<_>` and a type containing two `Bound` values",
issue = "30877")]
impl<T: ?Sized> RangeBounds<T> for RangeFull { impl<T: ?Sized> RangeBounds<T> for RangeFull {
fn start(&self) -> Bound<&T> { fn start_bound(&self) -> Bound<&T> {
Unbounded Unbounded
} }
fn end(&self) -> Bound<&T> { fn end_bound(&self) -> Bound<&T> {
Unbounded Unbounded
} }
} }
#[unstable(feature = "collections_range", #[stable(feature = "collections_range", since = "1.28.0")]
reason = "might be replaced with `Into<_>` and a type containing two `Bound` values",
issue = "30877")]
impl<T> RangeBounds<T> for RangeFrom<T> { impl<T> RangeBounds<T> for RangeFrom<T> {
fn start(&self) -> Bound<&T> { fn start_bound(&self) -> Bound<&T> {
Included(&self.start) Included(&self.start)
} }
fn end(&self) -> Bound<&T> { fn end_bound(&self) -> Bound<&T> {
Unbounded Unbounded
} }
} }
#[unstable(feature = "collections_range", #[stable(feature = "collections_range", since = "1.28.0")]
reason = "might be replaced with `Into<_>` and a type containing two `Bound` values",
issue = "30877")]
impl<T> RangeBounds<T> for RangeTo<T> { impl<T> RangeBounds<T> for RangeTo<T> {
fn start(&self) -> Bound<&T> { fn start_bound(&self) -> Bound<&T> {
Unbounded Unbounded
} }
fn end(&self) -> Bound<&T> { fn end_bound(&self) -> Bound<&T> {
Excluded(&self.end) Excluded(&self.end)
} }
} }
#[unstable(feature = "collections_range", #[stable(feature = "collections_range", since = "1.28.0")]
reason = "might be replaced with `Into<_>` and a type containing two `Bound` values",
issue = "30877")]
impl<T> RangeBounds<T> for Range<T> { impl<T> RangeBounds<T> for Range<T> {
fn start(&self) -> Bound<&T> { fn start_bound(&self) -> Bound<&T> {
Included(&self.start) Included(&self.start)
} }
fn end(&self) -> Bound<&T> { fn end_bound(&self) -> Bound<&T> {
Excluded(&self.end) Excluded(&self.end)
} }
} }
#[unstable(feature = "collections_range", #[stable(feature = "collections_range", since = "1.28.0")]
reason = "might be replaced with `Into<_>` and a type containing two `Bound` values",
issue = "30877")]
impl<T> RangeBounds<T> for RangeInclusive<T> { impl<T> RangeBounds<T> for RangeInclusive<T> {
fn start(&self) -> Bound<&T> { fn start_bound(&self) -> Bound<&T> {
Included(&self.start) Included(&self.start)
} }
fn end(&self) -> Bound<&T> { fn end_bound(&self) -> Bound<&T> {
Included(&self.end) Included(&self.end)
} }
} }
#[unstable(feature = "collections_range", #[stable(feature = "collections_range", since = "1.28.0")]
reason = "might be replaced with `Into<_>` and a type containing two `Bound` values",
issue = "30877")]
impl<T> RangeBounds<T> for RangeToInclusive<T> { impl<T> RangeBounds<T> for RangeToInclusive<T> {
fn start(&self) -> Bound<&T> { fn start_bound(&self) -> Bound<&T> {
Unbounded Unbounded
} }
fn end(&self) -> Bound<&T> { fn end_bound(&self) -> Bound<&T> {
Included(&self.end) Included(&self.end)
} }
} }
#[unstable(feature = "collections_range", #[stable(feature = "collections_range", since = "1.28.0")]
reason = "might be replaced with `Into<_>` and a type containing two `Bound` values",
issue = "30877")]
impl<T> RangeBounds<T> for (Bound<T>, Bound<T>) { impl<T> RangeBounds<T> for (Bound<T>, Bound<T>) {
fn start(&self) -> Bound<&T> { fn start_bound(&self) -> Bound<&T> {
match *self { match *self {
(Included(ref start), _) => Included(start), (Included(ref start), _) => Included(start),
(Excluded(ref start), _) => Excluded(start), (Excluded(ref start), _) => Excluded(start),
@ -799,7 +779,7 @@ impl<T> RangeBounds<T> for (Bound<T>, Bound<T>) {
} }
} }
fn end(&self) -> Bound<&T> { fn end_bound(&self) -> Bound<&T> {
match *self { match *self {
(_, Included(ref end)) => Included(end), (_, Included(ref end)) => Included(end),
(_, Excluded(ref end)) => Excluded(end), (_, Excluded(ref end)) => Excluded(end),
@ -808,75 +788,63 @@ impl<T> RangeBounds<T> for (Bound<T>, Bound<T>) {
} }
} }
#[unstable(feature = "collections_range", #[stable(feature = "collections_range", since = "1.28.0")]
reason = "might be replaced with `Into<_>` and a type containing two `Bound` values",
issue = "30877")]
impl<'a, T: ?Sized + 'a> RangeBounds<T> for (Bound<&'a T>, Bound<&'a T>) { impl<'a, T: ?Sized + 'a> RangeBounds<T> for (Bound<&'a T>, Bound<&'a T>) {
fn start(&self) -> Bound<&T> { fn start_bound(&self) -> Bound<&T> {
self.0 self.0
} }
fn end(&self) -> Bound<&T> { fn end_bound(&self) -> Bound<&T> {
self.1 self.1
} }
} }
#[unstable(feature = "collections_range", #[stable(feature = "collections_range", since = "1.28.0")]
reason = "might be replaced with `Into<_>` and a type containing two `Bound` values",
issue = "30877")]
impl<'a, T> RangeBounds<T> for RangeFrom<&'a T> { impl<'a, T> RangeBounds<T> for RangeFrom<&'a T> {
fn start(&self) -> Bound<&T> { fn start_bound(&self) -> Bound<&T> {
Included(self.start) Included(self.start)
} }
fn end(&self) -> Bound<&T> { fn end_bound(&self) -> Bound<&T> {
Unbounded Unbounded
} }
} }
#[unstable(feature = "collections_range", #[stable(feature = "collections_range", since = "1.28.0")]
reason = "might be replaced with `Into<_>` and a type containing two `Bound` values",
issue = "30877")]
impl<'a, T> RangeBounds<T> for RangeTo<&'a T> { impl<'a, T> RangeBounds<T> for RangeTo<&'a T> {
fn start(&self) -> Bound<&T> { fn start_bound(&self) -> Bound<&T> {
Unbounded Unbounded
} }
fn end(&self) -> Bound<&T> { fn end_bound(&self) -> Bound<&T> {
Excluded(self.end) Excluded(self.end)
} }
} }
#[unstable(feature = "collections_range", #[stable(feature = "collections_range", since = "1.28.0")]
reason = "might be replaced with `Into<_>` and a type containing two `Bound` values",
issue = "30877")]
impl<'a, T> RangeBounds<T> for Range<&'a T> { impl<'a, T> RangeBounds<T> for Range<&'a T> {
fn start(&self) -> Bound<&T> { fn start_bound(&self) -> Bound<&T> {
Included(self.start) Included(self.start)
} }
fn end(&self) -> Bound<&T> { fn end_bound(&self) -> Bound<&T> {
Excluded(self.end) Excluded(self.end)
} }
} }
#[unstable(feature = "collections_range", #[stable(feature = "collections_range", since = "1.28.0")]
reason = "might be replaced with `Into<_>` and a type containing two `Bound` values",
issue = "30877")]
impl<'a, T> RangeBounds<T> for RangeInclusive<&'a T> { impl<'a, T> RangeBounds<T> for RangeInclusive<&'a T> {
fn start(&self) -> Bound<&T> { fn start_bound(&self) -> Bound<&T> {
Included(self.start) Included(self.start)
} }
fn end(&self) -> Bound<&T> { fn end_bound(&self) -> Bound<&T> {
Included(self.end) Included(self.end)
} }
} }
#[unstable(feature = "collections_range", #[stable(feature = "collections_range", since = "1.28.0")]
reason = "might be replaced with `Into<_>` and a type containing two `Bound` values",
issue = "30877")]
impl<'a, T> RangeBounds<T> for RangeToInclusive<&'a T> { impl<'a, T> RangeBounds<T> for RangeToInclusive<&'a T> {
fn start(&self) -> Bound<&T> { fn start_bound(&self) -> Bound<&T> {
Unbounded Unbounded
} }
fn end(&self) -> Bound<&T> { fn end_bound(&self) -> Bound<&T> {
Included(self.end) Included(self.end)
} }
} }

View file

@ -119,12 +119,12 @@ impl<A: Array> ArrayVec<A> {
// the hole, and the vector length is restored to the new length. // the hole, and the vector length is restored to the new length.
// //
let len = self.len(); let len = self.len();
let start = match range.start() { let start = match range.start_bound() {
Included(&n) => n, Included(&n) => n,
Excluded(&n) => n + 1, Excluded(&n) => n + 1,
Unbounded => 0, Unbounded => 0,
}; };
let end = match range.end() { let end = match range.end_bound() {
Included(&n) => n + 1, Included(&n) => n + 1,
Excluded(&n) => n, Excluded(&n) => n,
Unbounded => len, Unbounded => len,

View file

@ -214,7 +214,7 @@ impl<K: Ord, V> SortedMap<K, V> {
fn range_slice_indices<R>(&self, range: R) -> (usize, usize) fn range_slice_indices<R>(&self, range: R) -> (usize, usize)
where R: RangeBounds<K> where R: RangeBounds<K>
{ {
let start = match range.start() { let start = match range.start_bound() {
Bound::Included(ref k) => { Bound::Included(ref k) => {
match self.lookup_index_for(k) { match self.lookup_index_for(k) {
Ok(index) | Err(index) => index Ok(index) | Err(index) => index
@ -229,7 +229,7 @@ impl<K: Ord, V> SortedMap<K, V> {
Bound::Unbounded => 0, Bound::Unbounded => 0,
}; };
let end = match range.end() { let end = match range.end_bound() {
Bound::Included(ref k) => { Bound::Included(ref k) => {
match self.lookup_index_for(k) { match self.lookup_index_for(k) {
Ok(index) => index + 1, Ok(index) => index + 1,