Skip to main content

Module range

Module range 

1.95.0 · Source
Expand description

§Replacement range types

The types within this module are meant to replace the legacy Range, RangeInclusive, RangeToInclusive and RangeFrom types in a future edition.

use core::range::{Range, RangeFrom, RangeInclusive, RangeToInclusive};

let arr = [0, 1, 2, 3, 4];
assert_eq!(arr[                        ..   ], [0, 1, 2, 3, 4]);
assert_eq!(arr[                        .. 3 ], [0, 1, 2      ]);
assert_eq!(arr[RangeToInclusive::from( ..=3)], [0, 1, 2, 3   ]);
assert_eq!(arr[       RangeFrom::from(1..  )], [   1, 2, 3, 4]);
assert_eq!(arr[           Range::from(1..3 )], [   1, 2      ]);
assert_eq!(arr[  RangeInclusive::from(1..=3)], [   1, 2, 3   ]);

Modules§

legacyExperimental
Legacy range types

Structs§

Range
A (half-open) range bounded inclusively below and exclusively above (start..end in a future edition).
RangeFrom
A range only bounded inclusively below (start..).
RangeFromIter
By-value RangeFrom iterator.
RangeInclusive
A range bounded inclusively below and above (start..=last).
RangeInclusiveIter
By-value RangeInclusive iterator.
RangeIter
By-value Range iterator.
RangeToInclusive
A range only bounded inclusively above (..=last).