[][src]Trait decorum::cmp::IntrinsicOrd

pub trait IntrinsicOrd: Copy + PartialOrd + Sized {
    fn is_undefined(&self) -> bool;
fn min_max_or_undefined(&self, other: &Self) -> (Self, Self); fn min_or_undefined(&self, other: &Self) -> Self { ... }
fn max_or_undefined(&self, other: &Self) -> Self { ... } }

Partial ordering of types with intrinsic representations for undefined comparisons.

IntrinsicOrd is similar to PartialOrd, but provides a pairwise minimum-maximum API and, for types without a total ordering, is only implemented for such types that additionally have intrinsic representations for undefined, such as the None variant of Option and NaNs for floating-point primitives. PrimitiveOrd is also closed and always compares two values of the same type.

This trait is also implemented for numeric types with total orderings, and can be used for comparisons that propagate NaNs for floating-point primitives (unlike PartialOrd, which expresses comparisons of types T and U with the extrinsic type Option<Ordering>).

See the min_or_undefined and max_or_undefined functions.

Required methods

fn is_undefined(&self) -> bool

Returns true if a value encodes undefined, otherwise false.

Prefer this predicate over direct comparisons. For floating-point representations, NaN is considered undefined, but direct comparisons with NaN values should be avoided.

fn min_max_or_undefined(&self, other: &Self) -> (Self, Self)

Compares two values and returns their pairwise minimum and maximum.

This function returns a representation of undefined for both the minimum and maximum if either of the inputs are undefined or the inputs cannot be compared, even if undefined values are ordered or the type has a total ordering. Undefined values are always propagated.

Examples

Propagating NaN values when comparing proxy types with a total ordering:

use decorum::cmp::{self, IntrinsicOrd};
use decorum::{Nan, Total};

let x: Total<f64> = 0.0.into();
let y: Total<f64> = (0.0 / 0.0).into(); // `NaN`.

// `Total` provides a total ordering in which zero is less than `NaN`, but `NaN`
// is considered undefined and is the result of the intrinsic comparison.
assert!(y.is_undefined());
assert!(cmp::min_or_undefined(x, y).is_undefined());
Loading content...

Provided methods

fn min_or_undefined(&self, other: &Self) -> Self

fn max_or_undefined(&self, other: &Self) -> Self

Loading content...

Implementations on Foreign Types

impl IntrinsicOrd for isize[src]

impl IntrinsicOrd for i8[src]

impl IntrinsicOrd for i16[src]

impl IntrinsicOrd for i32[src]

impl IntrinsicOrd for i64[src]

impl IntrinsicOrd for i128[src]

impl IntrinsicOrd for usize[src]

impl IntrinsicOrd for u8[src]

impl IntrinsicOrd for u16[src]

impl IntrinsicOrd for u32[src]

impl IntrinsicOrd for u64[src]

impl IntrinsicOrd for u128[src]

impl IntrinsicOrd for f32[src]

impl IntrinsicOrd for f64[src]

impl<T> IntrinsicOrd for Option<T> where
    T: Copy + PartialOrd
[src]

Loading content...

Implementors

impl<T, P> IntrinsicOrd for ConstrainedFloat<T, P> where
    T: Float + IntrinsicOrd + Primitive,
    P: Constraint<T>, 
[src]

Loading content...