Skip to content

Commit 688cbda

Browse files
author
Clar Charr
committed
Move RangeArgument and Bound to libcore.
1 parent 968ae7b commit 688cbda

File tree

3 files changed

+217
-196
lines changed

3 files changed

+217
-196
lines changed

src/libcollections/lib.rs

+2-51
Original file line numberDiff line numberDiff line change
@@ -136,60 +136,11 @@ mod std {
136136
pub use core::ops; // RangeFull
137137
}
138138

139-
/// An endpoint of a range of keys.
140-
///
141-
/// # Examples
142-
///
143-
/// `Bound`s are range endpoints:
144-
///
145-
/// ```
146-
/// #![feature(collections_range)]
147-
///
148-
/// use std::collections::range::RangeArgument;
149-
/// use std::collections::Bound::*;
150-
///
151-
/// assert_eq!((..100).start(), Unbounded);
152-
/// assert_eq!((1..12).start(), Included(&1));
153-
/// assert_eq!((1..12).end(), Excluded(&12));
154-
/// ```
155-
///
156-
/// Using a tuple of `Bound`s as an argument to [`BTreeMap::range`].
157-
/// Note that in most cases, it's better to use range syntax (`1..5`) instead.
158-
///
159-
/// ```
160-
/// use std::collections::BTreeMap;
161-
/// use std::collections::Bound::{Excluded, Included, Unbounded};
162-
///
163-
/// let mut map = BTreeMap::new();
164-
/// map.insert(3, "a");
165-
/// map.insert(5, "b");
166-
/// map.insert(8, "c");
167-
///
168-
/// for (key, value) in map.range((Excluded(3), Included(8))) {
169-
/// println!("{}: {}", key, value);
170-
/// }
171-
///
172-
/// assert_eq!(Some((&3, &"a")), map.range((Unbounded, Included(5))).next());
173-
/// ```
174-
///
175-
/// [`BTreeMap::range`]: btree_map/struct.BTreeMap.html#method.range
176-
#[stable(feature = "collections_bound", since = "1.17.0")]
177-
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)]
178-
pub enum Bound<T> {
179-
/// An inclusive bound.
180-
#[stable(feature = "collections_bound", since = "1.17.0")]
181-
Included(T),
182-
/// An exclusive bound.
183-
#[stable(feature = "collections_bound", since = "1.17.0")]
184-
Excluded(T),
185-
/// An infinite endpoint. Indicates that there is no bound in this direction.
186-
#[stable(feature = "collections_bound", since = "1.17.0")]
187-
Unbounded,
188-
}
189-
190139
/// An intermediate trait for specialization of `Extend`.
191140
#[doc(hidden)]
192141
trait SpecExtend<I: IntoIterator> {
193142
/// Extends `self` with the contents of the given iterator.
194143
fn spec_extend(&mut self, iter: I);
195144
}
145+
146+
pub use core::ops::Bound;

src/libcollections/range.rs

+1-145
Original file line numberDiff line numberDiff line change
@@ -8,151 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![unstable(feature = "collections_range",
12-
reason = "waiting for dust to settle on inclusive ranges",
13-
issue = "30877")]
1411

1512
//! Range syntax.
1613
17-
use core::ops::{RangeFull, Range, RangeTo, RangeFrom, RangeInclusive, RangeToInclusive};
18-
use Bound::{self, Excluded, Included, Unbounded};
19-
20-
/// `RangeArgument` is implemented by Rust's built-in range types, produced
21-
/// by range syntax like `..`, `a..`, `..b` or `c..d`.
22-
pub trait RangeArgument<T: ?Sized> {
23-
/// Start index bound.
24-
///
25-
/// Returns the start value as a `Bound`.
26-
///
27-
/// # Examples
28-
///
29-
/// ```
30-
/// #![feature(collections)]
31-
/// #![feature(collections_range)]
32-
///
33-
/// extern crate collections;
34-
///
35-
/// # fn main() {
36-
/// use collections::range::RangeArgument;
37-
/// use collections::Bound::*;
38-
///
39-
/// assert_eq!((..10).start(), Unbounded);
40-
/// assert_eq!((3..10).start(), Included(&3));
41-
/// # }
42-
/// ```
43-
fn start(&self) -> Bound<&T>;
44-
45-
/// End index bound.
46-
///
47-
/// Returns the end value as a `Bound`.
48-
///
49-
/// # Examples
50-
///
51-
/// ```
52-
/// #![feature(collections)]
53-
/// #![feature(collections_range)]
54-
///
55-
/// extern crate collections;
56-
///
57-
/// # fn main() {
58-
/// use collections::range::RangeArgument;
59-
/// use collections::Bound::*;
60-
///
61-
/// assert_eq!((3..).end(), Unbounded);
62-
/// assert_eq!((3..10).end(), Excluded(&10));
63-
/// # }
64-
/// ```
65-
fn end(&self) -> Bound<&T>;
66-
}
67-
68-
// FIXME add inclusive ranges to RangeArgument
69-
70-
impl<T: ?Sized> RangeArgument<T> for RangeFull {
71-
fn start(&self) -> Bound<&T> {
72-
Unbounded
73-
}
74-
fn end(&self) -> Bound<&T> {
75-
Unbounded
76-
}
77-
}
78-
79-
impl<T> RangeArgument<T> for RangeFrom<T> {
80-
fn start(&self) -> Bound<&T> {
81-
Included(&self.start)
82-
}
83-
fn end(&self) -> Bound<&T> {
84-
Unbounded
85-
}
86-
}
87-
88-
impl<T> RangeArgument<T> for RangeTo<T> {
89-
fn start(&self) -> Bound<&T> {
90-
Unbounded
91-
}
92-
fn end(&self) -> Bound<&T> {
93-
Excluded(&self.end)
94-
}
95-
}
96-
97-
impl<T> RangeArgument<T> for Range<T> {
98-
fn start(&self) -> Bound<&T> {
99-
Included(&self.start)
100-
}
101-
fn end(&self) -> Bound<&T> {
102-
Excluded(&self.end)
103-
}
104-
}
105-
106-
#[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")]
107-
impl<T> RangeArgument<T> for RangeInclusive<T> {
108-
fn start(&self) -> Bound<&T> {
109-
match *self {
110-
RangeInclusive::Empty{ ref at } => Included(at),
111-
RangeInclusive::NonEmpty { ref start, .. } => Included(start),
112-
}
113-
}
114-
fn end(&self) -> Bound<&T> {
115-
match *self {
116-
RangeInclusive::Empty{ ref at } => Excluded(at),
117-
RangeInclusive::NonEmpty { ref end, .. } => Included(end),
118-
}
119-
}
120-
}
121-
122-
#[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")]
123-
impl<T> RangeArgument<T> for RangeToInclusive<T> {
124-
fn start(&self) -> Bound<&T> {
125-
Unbounded
126-
}
127-
fn end(&self) -> Bound<&T> {
128-
Included(&self.end)
129-
}
130-
}
131-
132-
impl<T> RangeArgument<T> for (Bound<T>, Bound<T>) {
133-
fn start(&self) -> Bound<&T> {
134-
match *self {
135-
(Included(ref start), _) => Included(start),
136-
(Excluded(ref start), _) => Excluded(start),
137-
(Unbounded, _) => Unbounded,
138-
}
139-
}
140-
141-
fn end(&self) -> Bound<&T> {
142-
match *self {
143-
(_, Included(ref end)) => Included(end),
144-
(_, Excluded(ref end)) => Excluded(end),
145-
(_, Unbounded) => Unbounded,
146-
}
147-
}
148-
}
149-
150-
impl<'a, T: ?Sized + 'a> RangeArgument<T> for (Bound<&'a T>, Bound<&'a T>) {
151-
fn start(&self) -> Bound<&T> {
152-
self.0
153-
}
154-
155-
fn end(&self) -> Bound<&T> {
156-
self.1
157-
}
158-
}
14+
pub use core::ops::RangeArgument;

0 commit comments

Comments
 (0)