1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 #![unstable(feature = "collections_range",
12 reason = "waiting for dust to settle on inclusive ranges",
17 use core::ops::{RangeFull, Range, RangeTo, RangeFrom};
18 use Bound::{self, Excluded, Included, Unbounded};
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> {
25 /// Return start value as a `Bound`
30 /// #![feature(collections)]
31 /// #![feature(collections_range)]
32 /// #![feature(collections_bound)]
34 /// extern crate collections;
37 /// use collections::range::RangeArgument;
38 /// use collections::Bound::*;
40 /// assert_eq!((..10).start(), Unbounded);
41 /// assert_eq!((3..10).start(), Included(&3));
44 fn start(&self) -> Bound<&T>;
48 /// Return end value as a `Bound`
53 /// #![feature(collections)]
54 /// #![feature(collections_range)]
55 /// #![feature(collections_bound)]
57 /// extern crate collections;
60 /// use collections::range::RangeArgument;
61 /// use collections::Bound::*;
63 /// assert_eq!((3..).end(), Unbounded);
64 /// assert_eq!((3..10).end(), Excluded(&10));
67 fn end(&self) -> Bound<&T>;
70 // FIXME add inclusive ranges to RangeArgument
72 impl<T: ?Sized> RangeArgument<T> for RangeFull {
73 fn start(&self) -> Bound<&T> {
76 fn end(&self) -> Bound<&T> {
81 impl<T> RangeArgument<T> for RangeFrom<T> {
82 fn start(&self) -> Bound<&T> {
85 fn end(&self) -> Bound<&T> {
90 impl<T> RangeArgument<T> for RangeTo<T> {
91 fn start(&self) -> Bound<&T> {
94 fn end(&self) -> Bound<&T> {
99 impl<T> RangeArgument<T> for Range<T> {
100 fn start(&self) -> Bound<&T> {
101 Included(&self.start)
103 fn end(&self) -> Bound<&T> {
108 impl<T> RangeArgument<T> for (Bound<T>, Bound<T>) {
109 fn start(&self) -> Bound<&T> {
111 (Included(ref start), _) => Included(start),
112 (Excluded(ref start), _) => Excluded(start),
113 (Unbounded, _) => Unbounded,
117 fn end(&self) -> Bound<&T> {
119 (_, Included(ref end)) => Included(end),
120 (_, Excluded(ref end)) => Excluded(end),
121 (_, Unbounded) => Unbounded,
126 impl<'a, T: ?Sized + 'a> RangeArgument<T> for (Bound<&'a T>, Bound<&'a T>) {
127 fn start(&self) -> Bound<&T> {
131 fn end(&self) -> Bound<&T> {