pub trait IntRangeExt<T: Integer>where
Self: RangeBounds<T>,{
// Required methods
fn is_empty(&self) -> bool;
fn to_inclusive(&self) -> Result<RangeInclusive<T>, Error>;
fn contains_subrange<Other: RangeBounds<T>>(
&self,
other: &Other,
) -> Result<bool, Error>;
fn equal<Other: RangeBounds<T>>(&self, other: &Other) -> bool;
fn substract<Other: RangeBounds<T>>(
&self,
other: &Other,
) -> Result<(Option<RangeInclusive<T>>, Option<RangeInclusive<T>>), Error>;
fn intersect<Other: RangeBounds<T>>(
&self,
other: &Other,
) -> Result<bool, Error>;
}Required Methods§
Sourcefn is_empty(&self) -> bool
fn is_empty(&self) -> bool
Check if the range is empty
assert_eq!((0..0).is_empty(), true);
assert_eq!((0..1).is_empty(), false);Sourcefn to_inclusive(&self) -> Result<RangeInclusive<T>, Error>
fn to_inclusive(&self) -> Result<RangeInclusive<T>, Error>
self must not be empty
use int_range_ext::IntRangeExt;
assert_eq!((0..10).to_inclusive(), Ok(0..=9));
assert!((0..0).to_inclusive().is_err());Sourcefn contains_subrange<Other: RangeBounds<T>>(
&self,
other: &Other,
) -> Result<bool, Error>
fn contains_subrange<Other: RangeBounds<T>>( &self, other: &Other, ) -> Result<bool, Error>
Both self and other must not be empty
use int_range_ext::IntRangeExt;
assert_eq!((0..10).contains_subrange(&(1..8)), Ok(true));
assert_eq!((0..10).contains_subrange(&(1..11)), Ok(false));
assert!((0..10).contains_subrange(&(11..11)).is_err());Sourcefn equal<Other: RangeBounds<T>>(&self, other: &Other) -> bool
fn equal<Other: RangeBounds<T>>(&self, other: &Other) -> bool
use int_range_ext::IntRangeExt;
assert!((0..10).equal(&(0..=9)));Sourcefn substract<Other: RangeBounds<T>>(
&self,
other: &Other,
) -> Result<(Option<RangeInclusive<T>>, Option<RangeInclusive<T>>), Error>
fn substract<Other: RangeBounds<T>>( &self, other: &Other, ) -> Result<(Option<RangeInclusive<T>>, Option<RangeInclusive<T>>), Error>
self must contains_subrange other
use int_range_ext::IntRangeExt;
assert_eq!((0..10).substract(&(4..=7)), Ok((Some(0..=3), Some(8..=9))));
assert_eq!((0..10).substract(&(0..=7)), Ok((None, Some(8..=9))));
assert!((0..10).substract(&(4..=11)).is_err());Sourcefn intersect<Other: RangeBounds<T>>(&self, other: &Other) -> Result<bool, Error>
fn intersect<Other: RangeBounds<T>>(&self, other: &Other) -> Result<bool, Error>
Both self and other must not be empty
use int_range_ext::IntRangeExt;
assert_eq!((0..10).intersect(&(0..=7)), Ok(true));
assert_eq!((0..10).intersect(&(4..=11)), Ok(true));
assert_eq!((0..10).intersect(&(10..20)), Ok(false));
assert!((0..10).intersect(&(10..10)).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.