Skip to main content

RangeVal

Struct RangeVal 

Source
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

Source

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.

Source

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.

Source

pub const fn start(&self) -> i64

The lower bound (inclusive).

Source

pub const fn end(&self) -> i64

The upper bound (exclusive).

Source

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.

Source

pub const fn is_empty(&self) -> bool

Whether the range contains no integers.

Source

pub fn get(&self, index: i64) -> Option<i64>

The index-th integer, or None if index is outside the range.

The addition is done in i128 and checked on the way back, so a nonsensical index cannot wrap into a value the range does not contain.

Trait Implementations§

Source§

impl Clone for RangeVal

Source§

fn clone(&self) -> RangeVal

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for RangeVal

Source§

impl Debug for RangeVal

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for RangeVal

Source§

impl PartialEq for RangeVal

Source§

fn eq(&self, other: &RangeVal) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for RangeVal

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.