Skip to content

Commit

Permalink
add impl for RangeToInclusive
Browse files Browse the repository at this point in the history
  • Loading branch information
djzin committed Feb 18, 2017
1 parent 65c876f commit 4338290
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/libcollections/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

//! Range syntax.

use core::ops::{RangeFull, Range, RangeTo, RangeFrom, RangeInclusive};
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
Expand Down Expand Up @@ -121,6 +121,16 @@ impl<T> RangeArgument<T> for RangeInclusive<T> {
}
}

#[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 {
Expand Down
2 changes: 2 additions & 0 deletions src/libcollectionstest/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ fn test_range_inclusive() {
check(map.range(0...size - 1), map.range(..size));
check(map.range(-1...-1), vec![]);
check(map.range(-1...size), map.range(..));
check(map.range(...size), map.range(..));
check(map.range(...200), map.range(..201));
check(map.range(5...8), vec![(&5, &5), (&6, &6), (&7, &7), (&8, &8)]);
check(map.range(-1...0), vec![(&0, &0)]);
check(map.range(-1...2), vec![(&0, &0), (&1, &1), (&2, &2)]);
Expand Down
5 changes: 5 additions & 0 deletions src/libcollectionstest/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,11 @@ fn test_drain_inclusive_range() {
for _ in v.drain(0...3) {
}
assert_eq!(v, &["4".to_string(), "5".to_string()]);

let mut v: Vec<_> = (0...1).map(|x| x.to_string()).collect();
for _ in v.drain(...0) {
}
assert_eq!(v, &["1".to_string()]);
}

#[test]
Expand Down

0 comments on commit 4338290

Please sign in to comment.