Skip to content

Commit c174382

Browse files
author
Clar Charr
committed
Move RangeArgument to core.
1 parent 1c6e9e5 commit c174382

File tree

12 files changed

+165
-170
lines changed

12 files changed

+165
-170
lines changed

src/libcollections/btree/map.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@ use core::fmt::Debug;
1313
use core::hash::{Hash, Hasher};
1414
use core::iter::{FromIterator, Peekable, FusedIterator};
1515
use core::marker::PhantomData;
16-
use core::ops::Index;
16+
use core::ops::{Index, RangeArgument};
1717
use core::{fmt, intrinsics, mem, ptr};
1818

1919
use borrow::Borrow;
2020
use Bound::{Excluded, Included, Unbounded};
21-
use range::RangeArgument;
2221

2322
use super::node::{self, Handle, NodeRef, marker};
2423
use super::search;

src/libcollections/btree/set.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@ use core::cmp::{min, max};
1616
use core::fmt::Debug;
1717
use core::fmt;
1818
use core::iter::{Peekable, FromIterator, FusedIterator};
19-
use core::ops::{BitOr, BitAnd, BitXor, Sub};
19+
use core::ops::{BitOr, BitAnd, BitXor, Sub, RangeArgument};
2020

2121
use borrow::Borrow;
2222
use btree_map::{BTreeMap, Keys};
2323
use super::Recover;
24-
use range::RangeArgument;
2524

2625
// FIXME(conventions): implement bounded iterators
2726

src/libcollections/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ mod btree;
106106
pub mod borrow;
107107
pub mod fmt;
108108
pub mod linked_list;
109-
pub mod range;
110109
pub mod slice;
111110
pub mod str;
112111
pub mod string;

src/libcollections/range.rs

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

src/libcollections/string.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,13 @@ use alloc::str as alloc_str;
6161
use core::fmt;
6262
use core::hash;
6363
use core::iter::{FromIterator, FusedIterator};
64-
use core::ops::{self, Add, AddAssign, Index, IndexMut};
64+
use core::ops::{self, Add, AddAssign, Index, IndexMut, RangeArgument};
6565
use core::ptr;
6666
use core::str as core_str;
6767
use core::str::pattern::Pattern;
6868
use std_unicode::char::{decode_utf16, REPLACEMENT_CHARACTER};
6969

7070
use borrow::{Cow, ToOwned};
71-
use range::RangeArgument;
7271
use Bound::{Excluded, Included, Unbounded};
7372
use str::{self, FromStr, Utf8Error, Chars};
7473
use vec::Vec;

src/libcollections/vec.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,11 @@ use core::mem;
7979
#[cfg(not(test))]
8080
use core::num::Float;
8181
use core::ops::{InPlace, Index, IndexMut, Place, Placer};
82-
use core::ops;
82+
use core::ops::{self, RangeArgument};
8383
use core::ptr;
8484
use core::ptr::Shared;
8585
use core::slice;
8686

87-
use super::range::RangeArgument;
8887
use Bound::{Excluded, Included, Unbounded};
8988

9089
/// A contiguous growable array type, written `Vec<T>` but pronounced 'vector'.

src/libcollections/vec_deque.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use core::cmp::Ordering;
2121
use core::fmt;
2222
use core::iter::{repeat, FromIterator, FusedIterator};
2323
use core::mem;
24-
use core::ops::{Index, IndexMut, Place, Placer, InPlace};
24+
use core::ops::{Index, IndexMut, Place, Placer, InPlace, RangeArgument};
2525
use core::ptr;
2626
use core::ptr::Shared;
2727
use core::slice;
@@ -31,7 +31,6 @@ use core::cmp;
3131

3232
use alloc::raw_vec::RawVec;
3333

34-
use super::range::RangeArgument;
3534
use Bound::{Excluded, Included, Unbounded};
3635
use super::vec::Vec;
3736

src/libcore/ops/range.rs

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use collections::Bound::{self, Excluded, Included, Unbounded};
2+
13
/// An unbounded range. Use `..` (two dots) for its shorthand.
24
///
35
/// Its primary use case is slicing index. It cannot serve as an iterator
@@ -352,3 +354,156 @@ impl<Idx: PartialOrd<Idx>> RangeToInclusive<Idx> {
352354

353355
// RangeToInclusive<Idx> cannot impl From<RangeTo<Idx>>
354356
// because underflow would be possible with (..0).into()
357+
358+
/// `RangeArgument` is implemented by Rust's built-in range types, produced
359+
/// by range syntax like `..`, `a..`, `..b` or `c..d`.
360+
#![unstable(feature = "collections_range",
361+
reason = "waiting for dust to settle on inclusive ranges",
362+
issue = "30877")]
363+
pub trait RangeArgument<T: ?Sized> {
364+
/// Start index bound.
365+
///
366+
/// Returns the start value as a `Bound`.
367+
///
368+
/// # Examples
369+
///
370+
/// ```
371+
/// #![feature(collections)]
372+
/// #![feature(collections_range)]
373+
///
374+
/// extern crate collections;
375+
///
376+
/// # fn main() {
377+
/// use collections::range::RangeArgument;
378+
/// use collections::Bound::*;
379+
///
380+
/// assert_eq!((..10).start(), Unbounded);
381+
/// assert_eq!((3..10).start(), Included(&3));
382+
/// # }
383+
/// ```
384+
fn start(&self) -> Bound<&T>;
385+
386+
/// End index bound.
387+
///
388+
/// Returns the end value as a `Bound`.
389+
///
390+
/// # Examples
391+
///
392+
/// ```
393+
/// #![feature(collections)]
394+
/// #![feature(collections_range)]
395+
///
396+
/// extern crate collections;
397+
///
398+
/// # fn main() {
399+
/// use collections::range::RangeArgument;
400+
/// use collections::Bound::*;
401+
///
402+
/// assert_eq!((3..).end(), Unbounded);
403+
/// assert_eq!((3..10).end(), Excluded(&10));
404+
/// # }
405+
/// ```
406+
fn end(&self) -> Bound<&T>;
407+
}
408+
409+
#![unstable(feature = "collections_range",
410+
reason = "waiting for dust to settle on inclusive ranges",
411+
issue = "30877")]
412+
impl<T: ?Sized> RangeArgument<T> for RangeFull {
413+
fn start(&self) -> Bound<&T> {
414+
Unbounded
415+
}
416+
fn end(&self) -> Bound<&T> {
417+
Unbounded
418+
}
419+
}
420+
421+
#![unstable(feature = "collections_range",
422+
reason = "waiting for dust to settle on inclusive ranges",
423+
issue = "30877")]
424+
impl<T> RangeArgument<T> for RangeFrom<T> {
425+
fn start(&self) -> Bound<&T> {
426+
Included(&self.start)
427+
}
428+
fn end(&self) -> Bound<&T> {
429+
Unbounded
430+
}
431+
}
432+
433+
#![unstable(feature = "collections_range",
434+
reason = "waiting for dust to settle on inclusive ranges",
435+
issue = "30877")]
436+
impl<T> RangeArgument<T> for RangeTo<T> {
437+
fn start(&self) -> Bound<&T> {
438+
Unbounded
439+
}
440+
fn end(&self) -> Bound<&T> {
441+
Excluded(&self.end)
442+
}
443+
}
444+
445+
#![unstable(feature = "collections_range",
446+
reason = "waiting for dust to settle on inclusive ranges",
447+
issue = "30877")]
448+
impl<T> RangeArgument<T> for Range<T> {
449+
fn start(&self) -> Bound<&T> {
450+
Included(&self.start)
451+
}
452+
fn end(&self) -> Bound<&T> {
453+
Excluded(&self.end)
454+
}
455+
}
456+
457+
#[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")]
458+
impl<T> RangeArgument<T> for RangeInclusive<T> {
459+
fn start(&self) -> Bound<&T> {
460+
Included(&self.start)
461+
}
462+
fn end(&self) -> Bound<&T> {
463+
Included(&self.end)
464+
}
465+
}
466+
467+
#[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")]
468+
impl<T> RangeArgument<T> for RangeToInclusive<T> {
469+
fn start(&self) -> Bound<&T> {
470+
Unbounded
471+
}
472+
fn end(&self) -> Bound<&T> {
473+
Included(&self.end)
474+
}
475+
}
476+
477+
#![unstable(feature = "collections_range",
478+
reason = "waiting for dust to settle on inclusive ranges",
479+
issue = "30877")]
480+
impl<T> RangeArgument<T> for (Bound<T>, Bound<T>) {
481+
fn start(&self) -> Bound<&T> {
482+
match *self {
483+
(Included(ref start), _) => Included(start),
484+
(Excluded(ref start), _) => Excluded(start),
485+
(Unbounded, _) => Unbounded,
486+
}
487+
}
488+
489+
fn end(&self) -> Bound<&T> {
490+
match *self {
491+
(_, Included(ref end)) => Included(end),
492+
(_, Excluded(ref end)) => Excluded(end),
493+
(_, Unbounded) => Unbounded,
494+
}
495+
}
496+
}
497+
498+
#![unstable(feature = "collections_range",
499+
reason = "waiting for dust to settle on inclusive ranges",
500+
issue = "30877")]
501+
impl<'a, T: ?Sized + 'a> RangeArgument<T> for (Bound<&'a T>, Bound<&'a T>) {
502+
fn start(&self) -> Bound<&T> {
503+
self.0
504+
}
505+
506+
fn end(&self) -> Bound<&T> {
507+
self.1
508+
}
509+
}

0 commit comments

Comments
 (0)