Skip to main content

PartialRangeOrd

Trait PartialRangeOrd 

Source
pub trait PartialRangeOrd {
    // Required method
    fn partial_rcmp<R: RangeBounds<Self>, B: BorrowRange<Self, R>>(
        &self,
        range: B,
    ) -> RangePosition;
}
Expand description

Trait to provide the partial_rcmp method, which allows comparing the type to a range. A blanket implementation is provided for all types that implement the PartialOrd trait.

Required Methods§

Source

fn partial_rcmp<R: RangeBounds<Self>, B: BorrowRange<Self, R>>( &self, range: B, ) -> RangePosition

Compare the value to a range of values, returning its full RangePosition: the pair of its relationships to the lower and the upper bound.

Use RangePosition::ordering to collapse it into a simple RangeOrdering when the value is comparable with both bounds.

use range_cmp::{PartialRangeOrd, RangeOrdering};
assert_eq!(1.5_f64.partial_rcmp(2.0..3.0).ordering(), Some(RangeOrdering::Below));
assert_eq!(2.5_f64.partial_rcmp(2.0..3.0).ordering(), Some(RangeOrdering::Inside));
assert_eq!(3.5_f64.partial_rcmp(2.0..3.0).ordering(), Some(RangeOrdering::Above));
// `NaN` is incomparable with the bounds:
assert_eq!(core::f64::NAN.partial_rcmp(2.0..3.0).ordering(), None);

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§