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§
Sourcefn min_value() -> Self
fn min_value() -> Self
The minimum value for values of type Endpoint:
\[ \forall x : \mathtt{Self}, x \geq \mathtt{Self::min\_value}() \]
Sourcefn max_value() -> Self
fn max_value() -> Self
The maximum value for values of type Endpoint:
\[ \forall x : \mathtt{Self}, x \leq \mathtt{Self::max\_value}() \]
Sourcefn cmp_end(self, other: Self) -> Ordering
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
Sourcefn decrease_toward(self, other: Self) -> Option<Self>
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().
Sourcefn increase_toward(self, other: Self) -> Option<Self>
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§
Sourcefn next_after(self) -> Option<Self>
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}() \]
Sourcefn prev_before(self) -> Option<Self>
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.