Endpoint

Trait Endpoint 

Source
pub trait Endpoint: Copy {
    // Required methods
    fn min_value() -> Self;
    fn max_value() -> Self;
    fn is_valid(self) -> bool;
    fn cmp_end(self, other: Self) -> Ordering;
    fn decrease_toward(self, other: Self) -> Option<Self>;
    fn increase_toward(self, other: Self) -> Option<Self>;

    // Provided methods
    fn next_after(self) -> Option<Self> { ... }
    fn prev_before(self) -> Option<Self> { ... }
}
Expand description

An Endpoint is the left or right limit of a closed interval [left, right].

Endpoint types must have maximum and minimum values. For bounded integer types, that’s simply T::MIN or T::MAX; in general, types may have to be extended, just like floating point values have +/- infinity.

Endpoint types must also be enumerable in both ascending and descending order.

There is an implementation for all 10 primitive fixed-width integer types (signed/unsigned 8, 16, 32, 64, and 128 bits), for isize and usize, and for the IEEE floating point types f32 and f64.

Required Methods§

Source

fn min_value() -> Self

The minimum value for values of type Endpoint:

\[ \forall x : \mathtt{Self}, x \geq \mathtt{Self::min\_value}() \]

Source

fn max_value() -> Self

The maximum value for values of type Endpoint:

\[ \forall x : \mathtt{Self}, x \leq \mathtt{Self::max\_value}() \]

Source

fn is_valid(self) -> bool

Returns whether self is comparable.

Source

fn cmp_end(self, other: Self) -> Ordering

Compares self <=> other. Both self and other are guaranteed to satisfy Endpoint::is_valid(). Implementations may return an arbitrary ordering if that’s not the case.

See core::cmp::Ord

Source

fn decrease_toward(self, other: Self) -> Option<Self>

Returns prev_before() iff other < self, and None otherwise.

In practice, it’s usually easier to directly implement this method instead of prev_before() (other < self guarantees there is a previous value for self), so prev_before() is implemented in terms of Self::decrease_toward().

Source

fn increase_toward(self, other: Self) -> Option<Self>

Returns next_after() iff other > self, and None otherwise.

In practice, it’s usually easier to directly implement this method instead of next_after() (other > self guarantees there is a next value for self), so next_after() is implemented in terms of Self::increase_toward().

Provided Methods§

Source

fn next_after(self) -> Option<Self>

Returns the minimum Endpoint value strictly greater than self, or None if there is no such value (iff self == Self::max_value()).

\[ \forall \mathtt{self}, x: \mathtt{Self}, x > \mathtt{self} \Rightarrow x \geq \mathtt{self.next\_after}() \]

Source

fn prev_before(self) -> Option<Self>

Returns the maximum Endpoint value strictly less than self, or None if there is no such value (iff self == Self::min_value()).

\[ \forall \mathtt{self}, x: \mathtt{Self}, x < \mathtt{self} \Rightarrow x \leq \mathtt{self.prev\_before}() \]

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Endpoint for f32

Source§

fn min_value() -> f32

Source§

fn max_value() -> f32

Source§

fn is_valid(self) -> bool

Source§

fn cmp_end(self, other: Self) -> Ordering

Source§

fn decrease_toward(self, other: f32) -> Option<f32>

Source§

fn increase_toward(self, other: f32) -> Option<f32>

Source§

impl Endpoint for f64

Source§

fn min_value() -> f64

Source§

fn max_value() -> f64

Source§

fn is_valid(self) -> bool

Source§

fn cmp_end(self, other: Self) -> Ordering

Source§

fn decrease_toward(self, other: f64) -> Option<f64>

Source§

fn increase_toward(self, other: f64) -> Option<f64>

Source§

impl Endpoint for i8

Source§

fn min_value() -> i8

Source§

fn max_value() -> i8

Source§

fn is_valid(self) -> bool

Source§

fn cmp_end(self, other: Self) -> Ordering

Source§

fn decrease_toward(self, other: i8) -> Option<i8>

Source§

fn increase_toward(self, other: i8) -> Option<i8>

Source§

impl Endpoint for i16

Source§

fn min_value() -> i16

Source§

fn max_value() -> i16

Source§

fn is_valid(self) -> bool

Source§

fn cmp_end(self, other: Self) -> Ordering

Source§

fn decrease_toward(self, other: i16) -> Option<i16>

Source§

fn increase_toward(self, other: i16) -> Option<i16>

Source§

impl Endpoint for i32

Source§

fn min_value() -> i32

Source§

fn max_value() -> i32

Source§

fn is_valid(self) -> bool

Source§

fn cmp_end(self, other: Self) -> Ordering

Source§

fn decrease_toward(self, other: i32) -> Option<i32>

Source§

fn increase_toward(self, other: i32) -> Option<i32>

Source§

impl Endpoint for i64

Source§

fn min_value() -> i64

Source§

fn max_value() -> i64

Source§

fn is_valid(self) -> bool

Source§

fn cmp_end(self, other: Self) -> Ordering

Source§

fn decrease_toward(self, other: i64) -> Option<i64>

Source§

fn increase_toward(self, other: i64) -> Option<i64>

Source§

impl Endpoint for i128

Source§

impl Endpoint for isize

Source§

impl Endpoint for u8

Source§

fn min_value() -> u8

Source§

fn max_value() -> u8

Source§

fn is_valid(self) -> bool

Source§

fn cmp_end(self, other: Self) -> Ordering

Source§

fn decrease_toward(self, other: u8) -> Option<u8>

Source§

fn increase_toward(self, other: u8) -> Option<u8>

Source§

impl Endpoint for u16

Source§

fn min_value() -> u16

Source§

fn max_value() -> u16

Source§

fn is_valid(self) -> bool

Source§

fn cmp_end(self, other: Self) -> Ordering

Source§

fn decrease_toward(self, other: u16) -> Option<u16>

Source§

fn increase_toward(self, other: u16) -> Option<u16>

Source§

impl Endpoint for u32

Source§

fn min_value() -> u32

Source§

fn max_value() -> u32

Source§

fn is_valid(self) -> bool

Source§

fn cmp_end(self, other: Self) -> Ordering

Source§

fn decrease_toward(self, other: u32) -> Option<u32>

Source§

fn increase_toward(self, other: u32) -> Option<u32>

Source§

impl Endpoint for u64

Source§

fn min_value() -> u64

Source§

fn max_value() -> u64

Source§

fn is_valid(self) -> bool

Source§

fn cmp_end(self, other: Self) -> Ordering

Source§

fn decrease_toward(self, other: u64) -> Option<u64>

Source§

fn increase_toward(self, other: u64) -> Option<u64>

Source§

impl Endpoint for u128

Source§

impl Endpoint for usize

Implementors§