Skip to main content

RangeOrd

Trait RangeOrd 

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

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

Required Methods§

Source

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

Compare the value to a range of values. Returns whether the value is below, inside, above, or whether the range is empty.

use range_cmp::{RangeOrd, RangeOrdering};
assert_eq!(15.rcmp(20..30), RangeOrdering::Below);
assert_eq!(25.rcmp(20..30), RangeOrdering::Inside);
assert_eq!(35.rcmp(20..30), RangeOrdering::Above);
assert_eq!(25.rcmp(30..20), RangeOrdering::Empty);

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§

Source§

impl<T: Ord> RangeOrd for T