Trait RangeComparable

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

Trait to provide the range_cmp 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 range_cmp<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 or above the range.

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

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.

Implementors§