Skip to main content

OptionMinMax

Trait OptionMinMax 

pub trait OptionMinMax<Other, Inner = Other> {
    // Required methods
    fn opt_min(self, other: Other) -> Option<Inner>;
    fn opt_max(self, other: Other) -> Option<Inner>;
}
Expand description

Trait for values and Options that can be compared to get the minimum or maximum.

Implementing this type leads to the following auto-implementations:

  • OptionMinMax<Option<InnerRhs>> for T.
  • OptionMinMax<Rhs> for Option<T>.
  • OptionMinMax<Option<InnerRhs>> for Option<T>.
  • … and some variants with references.

This trait is auto-implemented for OptionOperations types implementing OptionOrd<Rhs>.

Required Methods§

fn opt_min(self, other: Other) -> Option<Inner>

Compares and returns the minimum of two values.

Returns None if they can’t be compared, e.g. if at most one argument is None.

fn opt_max(self, other: Other) -> Option<Inner>

Compares and returns the maximum of two values.

Returns None if they can’t be compared, e.g. if at most one argument is None.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

§

impl<T> OptionMinMax<Option<T>, T> for Option<T>
where T: for<'a> OptionOrd<&'a T, T>,

§

fn opt_min(self, other: Option<T>) -> Option<T>

§

fn opt_max(self, other: Option<T>) -> Option<T>

§

impl<T> OptionMinMax<T> for Option<T>
where T: for<'a> OptionOrd<&'a T, T>,

§

fn opt_min(self, other: T) -> Option<T>

§

fn opt_max(self, other: T) -> Option<T>

Implementors§

§

impl<T> OptionMinMax<Option<T>, T> for T
where T: for<'a> OptionOrd<&'a T, T>,

§

impl<T> OptionMinMax<T> for T
where T: for<'a> OptionOrd<&'a T, T>,