about summary refs log tree commit diff
path: root/src/libcollections
diff options
context:
space:
mode:
authorCorey Farwell <coreyf@rwell.org>2017-02-28 22:55:27 -0500
committerGitHub <noreply@github.com>2017-02-28 22:55:27 -0500
commit43df65fb3fe554d451ea88ec75ec8cc2991d1a3e (patch)
treeba1fb2f32f65317f8ab67f5288fd716313029a14 /src/libcollections
parent4ba49ab39f942af3846cf0d8599674b0adde94b5 (diff)
parent43382903a19ce209dee136e5f983003062b7ce78 (diff)
Rollup merge of #39936 - djzin:inclusive_rangeargument, r=alexcrichton
impl RangeArgument for RangeInclusive and add appropriate tests

Now that `RangeArgument` returns a `Bound`, the impl for `RangeInclusive` is natural to implement and all that's required are tests around it.
Diffstat (limited to 'src/libcollections')
-rw-r--r--src/libcollections/range.rs28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/libcollections/range.rs b/src/libcollections/range.rs
index 1df4ace3777..e4b94a1d70e 100644
--- a/src/libcollections/range.rs
+++ b/src/libcollections/range.rs
@@ -14,7 +14,7 @@
 
 //! Range syntax.
 
-use core::ops::{RangeFull, Range, RangeTo, RangeFrom};
+use core::ops::{RangeFull, Range, RangeTo, RangeFrom, RangeInclusive, RangeToInclusive};
 use Bound::{self, Excluded, Included, Unbounded};
 
 /// **RangeArgument** is implemented by Rust's built-in range types, produced
@@ -105,6 +105,32 @@ impl<T> RangeArgument<T> for Range<T> {
     }
 }
 
+#[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")]
+impl<T> RangeArgument<T> for RangeInclusive<T> {
+    fn start(&self) -> Bound<&T> {
+        match *self {
+            RangeInclusive::Empty{ ref at }            => Included(at),
+            RangeInclusive::NonEmpty { ref start, .. } => Included(start),
+        }
+    }
+    fn end(&self) -> Bound<&T> {
+        match *self {
+            RangeInclusive::Empty{ ref at }            => Excluded(at),
+            RangeInclusive::NonEmpty { ref end, .. }   => Included(end),
+        }
+    }
+}
+
+#[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")]
+impl<T> RangeArgument<T> for RangeToInclusive<T> {
+    fn start(&self) -> Bound<&T> {
+        Unbounded
+    }
+    fn end(&self) -> Bound<&T> {
+        Included(&self.end)
+    }
+}
+
 impl<T> RangeArgument<T> for (Bound<T>, Bound<T>) {
     fn start(&self) -> Bound<&T> {
         match *self {