IntRangeExt

Trait IntRangeExt 

Source
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§

Source

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);
Source

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());
Source

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());
Source

fn equal<Other: RangeBounds<T>>(&self, other: &Other) -> bool

use int_range_ext::IntRangeExt;

assert!((0..10).equal(&(0..=9)));
Source

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());
Source

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.

Implementors§

Source§

impl<T: Integer, U: RangeBounds<T>> IntRangeExt<T> for U