std::ops::Range

Struct std::ops::Range

pub struct Range<Idx> {
    pub start: Idx,
    pub end: Idx,
}

A (half-open) range which is bounded at both ends: { x | start <= x < end }. Use start..end (two dots) for its shorthand.

See the contains method for its characterization.

Examples

fn main() {
    assert_eq!((3..5), std::ops::Range{ start: 3, end: 5 });
    assert_eq!(3+4+5, (3..6).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]);
    assert_eq!(arr[1..3], [  1,2  ]);  // Range
}

Fields