Skip to content

Commit 4338290

Browse files
committed
add impl for RangeToInclusive
1 parent 65c876f commit 4338290

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

src/libcollections/range.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
//! Range syntax.
1616
17-
use core::ops::{RangeFull, Range, RangeTo, RangeFrom, RangeInclusive};
17+
use core::ops::{RangeFull, Range, RangeTo, RangeFrom, RangeInclusive, RangeToInclusive};
1818
use Bound::{self, Excluded, Included, Unbounded};
1919

2020
/// **RangeArgument** is implemented by Rust's built-in range types, produced
@@ -121,6 +121,16 @@ impl<T> RangeArgument<T> for RangeInclusive<T> {
121121
}
122122
}
123123

124+
#[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")]
125+
impl<T> RangeArgument<T> for RangeToInclusive<T> {
126+
fn start(&self) -> Bound<&T> {
127+
Unbounded
128+
}
129+
fn end(&self) -> Bound<&T> {
130+
Included(&self.end)
131+
}
132+
}
133+
124134
impl<T> RangeArgument<T> for (Bound<T>, Bound<T>) {
125135
fn start(&self) -> Bound<&T> {
126136
match *self {

src/libcollectionstest/btree/map.rs

+2
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ fn test_range_inclusive() {
200200
check(map.range(0...size - 1), map.range(..size));
201201
check(map.range(-1...-1), vec![]);
202202
check(map.range(-1...size), map.range(..));
203+
check(map.range(...size), map.range(..));
204+
check(map.range(...200), map.range(..201));
203205
check(map.range(5...8), vec![(&5, &5), (&6, &6), (&7, &7), (&8, &8)]);
204206
check(map.range(-1...0), vec![(&0, &0)]);
205207
check(map.range(-1...2), vec![(&0, &0), (&1, &1), (&2, &2)]);

src/libcollectionstest/vec.rs

+5
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,11 @@ fn test_drain_inclusive_range() {
528528
for _ in v.drain(0...3) {
529529
}
530530
assert_eq!(v, &["4".to_string(), "5".to_string()]);
531+
532+
let mut v: Vec<_> = (0...1).map(|x| x.to_string()).collect();
533+
for _ in v.drain(...0) {
534+
}
535+
assert_eq!(v, &["1".to_string()]);
531536
}
532537

533538
#[test]

0 commit comments

Comments
 (0)