Check

Trait Check 

Source
pub trait Check<R: RangeBounds<Self>>:
    Sized
    + PartialOrd
    + Copy {
    // Required method
    fn check_range(self, range: R) -> Result<Self, OutOfRangeError<Self>>;
}
Expand description

Trait that provides early returns for failed range checks using the Result type.

Required Methods§

Source

fn check_range(self, range: R) -> Result<Self, OutOfRangeError<Self>>

Checks whether self is within the given range. If it is, re-returns self. Otherwise, returns an Error that contains both the value and the range.

§Examples
use range_check::Check;

assert!(24680.check_range(1..99999).is_ok());
assert!(24680.check_range(1..9999).is_err());

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§

Source§

impl<T, R> Check<R> for T
where R: RangeBounds<T>, T: PartialOrd + Copy,