Struct std::ops::RangeFrom
[−]
[src]
pub struct RangeFrom<Idx> { pub start: Idx, }1.0.0
A range which is only bounded below: { x | start <= x }.
Use start..
for its shorthand.
See the contains()
method for its characterization.
Note: Currently, no overflow checking is done for the iterator implementation; if you use an integer range and the integer overflows, it might panic in debug mode or create an endless loop in release mode. This overflow behavior might change in the future.
Examples
#![feature(iter_arith)] fn main() { assert_eq!((2..), std::ops::RangeFrom{ start: 2 }); assert_eq!(2+3+4, (2..).take(3).sum()); let arr = [0, 1, 2, 3]; assert_eq!(arr[ .. ], [0,1,2,3]); assert_eq!(arr[ ..3], [0,1,2 ]); assert_eq!(arr[1.. ], [ 1,2,3]); // RangeFrom assert_eq!(arr[1..3], [ 1,2 ]); }#![feature(iter_arith)] fn main() { assert_eq!((2..), std::ops::RangeFrom{ start: 2 }); assert_eq!(2+3+4, (2..).take(3).sum()); let arr = [0, 1, 2, 3]; assert_eq!(arr[ .. ], [0,1,2,3]); assert_eq!(arr[ ..3], [0,1,2 ]); assert_eq!(arr[1.. ], [ 1,2,3]); // RangeFrom assert_eq!(arr[1..3], [ 1,2 ]); }
Fields
start | The lower bound of the range (inclusive). |
Methods
impl<A> RangeFrom<A> where A: Step
fn step_by(self, by: A) -> StepBy<A, RangeFrom<A>>
Creates an iterator starting at the same point, but stepping by the given amount at each iteration.
Examples
#![feature(step_by)] fn main() { for i in (0u8..).step_by(2).take(10) { println!("{}", i); } }for i in (0u8..).step_by(2).take(10) { println!("{}", i); }
This prints the first ten even natural integers (0 to 18).
impl<Idx> RangeFrom<Idx> where Idx: PartialOrd<Idx>
fn contains(&self, item: Idx) -> bool
Examples
#![feature(range_contains)] fn main() { assert!( ! (3..).contains(2)); assert!( (3..).contains(3)); assert!( (3..).contains(1_000_000_000)); }#![feature(range_contains)] fn main() { assert!( ! (3..).contains(2)); assert!( (3..).contains(3)); assert!( (3..).contains(1_000_000_000)); }