pub struct RangeVal { /* private fields */ }Expand description
The Range payload: a half-open [start, end) interval over Int.
The invariant end >= start is established by RangeVal::new and there is
no other constructor and no mutator, so an “inverted” range — one whose
length would be negative — is unrepresentable.
Implementations§
Source§impl RangeVal
impl RangeVal
Sourcepub const fn new(start: i64, end: i64) -> RangeVal
pub const fn new(start: i64, end: i64) -> RangeVal
The half-open range start..end, normalizing a descending range to the
empty range at start.
Sourcepub const fn new_inclusive(start: i64, end: i64) -> RangeVal
pub const fn new_inclusive(start: i64, end: i64) -> RangeVal
The inclusive range start..=end.
..=Int::MAX is the one input whose half-open equivalent does not exist:
its exclusive end is 2^63. It is not a fault — the range itself is
perfectly well defined — so it saturates, which loses nothing: the
element Int::MAX is still the last one, because there is no Int above
it to have excluded.
Sourcepub const fn len(&self) -> i128
pub const fn len(&self) -> i128
How many integers the range contains.
end - start in i128: the difference of two i64s does not fit an
i64 (0..Int::MAX is fine, but Int::MIN..Int::MAX is 2^64 - 1), and
a wrapping subtraction here would report a negative length for the
widest ranges — a for loop that ran zero times over every integer.