Enum std::ops::RangeInclusive
[−]
[src]
pub enum RangeInclusive<Idx> { Empty { at: Idx, }, NonEmpty { start: Idx, end: Idx, }, }
An inclusive range which is bounded at both ends: { x | start <= x <= end }.
Use start...end
(three dots) for its shorthand.
See the contains()
method for its characterization.
Examples
#![feature(inclusive_range,inclusive_range_syntax,iter_arith)] fn main() { assert_eq!((3...5), std::ops::RangeInclusive::NonEmpty{ start: 3, end: 5 }); assert_eq!(3+4+5, (3...5).sum()); let arr = [0, 1, 2, 3]; assert_eq!(arr[ ...2], [0,1,2 ]); assert_eq!(arr[1...2], [ 1,2 ]); // RangeInclusive }#![feature(inclusive_range,inclusive_range_syntax,iter_arith)] fn main() { assert_eq!((3...5), std::ops::RangeInclusive::NonEmpty{ start: 3, end: 5 }); assert_eq!(3+4+5, (3...5).sum()); let arr = [0, 1, 2, 3]; assert_eq!(arr[ ...2], [0,1,2 ]); assert_eq!(arr[1...2], [ 1,2 ]); // RangeInclusive }
Variants
Empty | Empty range (iteration has finished) Fields
| |||||
NonEmpty | Non-empty range (iteration will yield value(s)) Fields
|
Methods
impl<A> RangeInclusive<A> where A: Step
fn step_by(self, by: A) -> StepBy<A, RangeInclusive<A>>
Creates an iterator with the same range, but stepping by the given amount at each iteration.
The resulting iterator handles overflow by stopping.
Examples
#![feature(step_by, inclusive_range_syntax)] fn main() { for i in (0...10).step_by(2) { println!("{}", i); } }#![feature(step_by, inclusive_range_syntax)] for i in (0...10).step_by(2) { println!("{}", i); }
This prints:
0
2
4
6
8
10
impl<Idx> RangeInclusive<Idx> where Idx: PartialOrd<Idx>
fn contains(&self, item: Idx) -> bool
Examples
#![feature(range_contains,inclusive_range_syntax)] fn main() { assert!( ! (3...5).contains(2)); assert!( (3...5).contains(3)); assert!( (3...5).contains(4)); assert!( (3...5).contains(5)); assert!( ! (3...5).contains(6)); assert!( (3...3).contains(3)); assert!( ! (3...2).contains(3)); }#![feature(range_contains,inclusive_range_syntax)] fn main() { assert!( ! (3...5).contains(2)); assert!( (3...5).contains(3)); assert!( (3...5).contains(4)); assert!( (3...5).contains(5)); assert!( ! (3...5).contains(6)); assert!( (3...3).contains(3)); assert!( ! (3...2).contains(3)); }