From f166bd9857dac3c66e812ba6bc33e59494c3fef2 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Sun, 23 Apr 2017 21:14:32 -0700 Subject: Make RangeInclusive just a two-field struct Not being an enum improves ergonomics, especially since NonEmpty could be Empty. It can still be iterable without an extra "done" bit by making the range have !(start <= end), which is even possible without changing the Step trait. Implements RFC 1980 --- src/libcore/tests/lib.rs | 1 + src/libcore/tests/ops.rs | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) (limited to 'src/libcore/tests') diff --git a/src/libcore/tests/lib.rs b/src/libcore/tests/lib.rs index c52155ead4f..8c4cd1d0c84 100644 --- a/src/libcore/tests/lib.rs +++ b/src/libcore/tests/lib.rs @@ -22,6 +22,7 @@ #![feature(fmt_internals)] #![feature(iterator_step_by)] #![feature(i128_type)] +#![feature(inclusive_range)] #![feature(iter_rfind)] #![feature(libc)] #![feature(nonzero)] diff --git a/src/libcore/tests/ops.rs b/src/libcore/tests/ops.rs index 1c6c13b0d02..50aed15896c 100644 --- a/src/libcore/tests/ops.rs +++ b/src/libcore/tests/ops.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use core::ops::{Range, RangeFull, RangeFrom, RangeTo}; +use core::ops::{Range, RangeFull, RangeFrom, RangeTo, RangeInclusive}; // Test the Range structs without the syntactic sugar. @@ -47,3 +47,19 @@ fn test_full_range() { // Not much to test. let _ = RangeFull; } + +#[test] +fn test_range_inclusive() { + let mut r = RangeInclusive { start: 1i8, end: 2 }; + assert_eq!(r.next(), Some(1)); + assert_eq!(r.next(), Some(2)); + assert_eq!(r.next(), None); + + r = RangeInclusive { start: 127i8, end: 127 }; + assert_eq!(r.next(), Some(127)); + assert_eq!(r.next(), None); + + r = RangeInclusive { start: -128i8, end: -128 }; + assert_eq!(r.next_back(), Some(-128)); + assert_eq!(r.next_back(), None); +} \ No newline at end of file -- cgit 1.4.1-3-g733a5