pub trait Min: PartialOrd + Sized {
// Provided methods
fn min<'a>(&'a self, other: &'a Self) -> &'a Self { ... }
fn min_by_value(self, other: Self) -> Self { ... }
}
Expand description
A trait for finding the minimum of two values.
This trait provides a min
method that returns a reference to the lesser of
two values. It is bounded by PartialOrd
.
§Implementations
- For types that already guarantee validity, like
RealValidated
, the default implementation is sufficient and safe. - A specialized implementation is provided for
f64
to add validation checks in debug builds.
§Behavior with NaN
For f64
, if either input is NaN
, the comparison self <= other
is false
, which means other
will be returned. Note that in debug builds,
providing a NaN
input will cause a panic.
RealValidated
types should not contain NaN
values by contract.
Provided Methods§
Sourcefn min<'a>(&'a self, other: &'a Self) -> &'a Self
fn min<'a>(&'a self, other: &'a Self) -> &'a Self
Returns a reference to the minimum of self
and other
.
§Examples
use num_valid::functions::Min;
assert_eq!(Min::min(&5.0, &3.0), &3.0);
assert_eq!(Min::min(&-10.0, &-5.0), &-10.0);
Sourcefn min_by_value(self, other: Self) -> Self
fn min_by_value(self, other: Self) -> Self
Returns the minimum of self
and other
, consuming both values.
§Examples
use num_valid::functions::Min;
assert_eq!(5.0f64.min_by_value(3.0), 3.0);
assert_eq!((-10.0f64).min_by_value(-5.0), -10.0);
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.