Struct RangeList

Source
pub struct RangeList<E: PartialOrd> { /* private fields */ }
Expand description

A sorted collection of inclusive ranges that can be used to represent non-continuous sets of values.

§Warning

Although RangeList can be constructed for elements that do not implement std::cmp::Ord, but do implement std::cmp::PartialOrd, constructor methods, such as the FromIterator implementation, will panic if the used boundary values cannot be sorted. This requirement allows the usage of types like f64, as long as the user can guarantee that values that cannot be ordered, like NaN, will not appear.

Implementations§

Source§

impl<E: PartialOrd> RangeList<E>

Source

pub fn is_empty(&self) -> bool

Returns true if the range list contains no items.

§Examples
assert!(!RangeList::from_iter([3..=4]).is_empty());
assert!(RangeList::<i64>::default().is_empty());
assert!(RangeList::from_iter([3..=2]).is_empty());
Source

pub fn contains(&self, item: &E) -> bool

Returns true if item is contained in the range list.

§Examples
assert!(RangeList::from_iter([1..=4]).contains(&4));
assert!(!RangeList::from_iter([1..=4]).contains(&0));

assert!(RangeList::from_iter([1..=4, 6..=7, -5..=-3]).contains(&7));
assert!(!RangeList::from_iter([1..=4, 6..=7, -5..=-3]).contains(&0));
Source

pub fn lower_bound(&self) -> Option<&E>

Returns the lower bound of the range list, or None if the range list is empty.

§Examples
assert_eq!(RangeList::from_iter([1..=4]).lower_bound(), Some(&1));
assert_eq!(RangeList::from_iter([1..=4, 6..=7, -5..=-3]).lower_bound(), Some(&-5));

assert_eq!(RangeList::<i64>::default().lower_bound(), None);
Source

pub fn upper_bound(&self) -> Option<&E>

Returns the upper bound of the range list, or None if the range list is empty

§Examples
assert_eq!(RangeList::from_iter([1..=4]).upper_bound(), Some(&4));
assert_eq!(RangeList::from_iter([1..=4, 6..=7, -5..=-3]).upper_bound(), Some(&7));

assert_eq!(RangeList::<i64>::default().upper_bound(), None);
Source§

impl<E: PartialOrd + Copy> RangeList<E>

Source

pub fn iter<'a>( &'a self, ) -> Map<<&RangeList<E> as IntoIterator>::IntoIter, fn(RangeInclusive<&'a E>) -> RangeInclusive<E>>

Returns an Copying iterator for the ranges in the set.

Trait Implementations§

Source§

impl<E: Clone + PartialOrd> Clone for RangeList<E>

Source§

fn clone(&self) -> RangeList<E>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<E: PartialOrd + Debug> Debug for RangeList<E>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<E: Default + PartialOrd> Default for RangeList<E>

Source§

fn default() -> RangeList<E>

Returns the “default value” for a type. Read more
Source§

impl<E: PartialOrd + Debug> Display for RangeList<E>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<E: PartialOrd + Clone> From<&RangeInclusive<E>> for RangeList<E>

Source§

fn from(value: &RangeInclusive<E>) -> Self

Converts to this type from the input type.
Source§

impl<E: PartialOrd + Clone> From<RangeInclusive<E>> for RangeList<E>

Source§

fn from(value: RangeInclusive<E>) -> Self

Converts to this type from the input type.
Source§

impl<E, R> FromIterator<R> for RangeList<E>
where E: PartialOrd + Clone, R: Into<RangeInclusive<E>>,

Source§

fn from_iter<T: IntoIterator<Item = R>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl<E: Hash + PartialOrd> Hash for RangeList<E>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<E: PartialOrd + Clone> IntervalIterator<E> for RangeList<E>

Source§

type IntervalIter = <RangeList<E> as IntoIterator>::IntoIter

The type of the interval iterator.
Source§

fn intervals(&self) -> Self::IntervalIter

Returns an iterator over the ordered intervals.
Source§

fn card(&self) -> usize

Returns the number of elements contained within the RangeList.
Source§

fn diff<O, R>(&self, other: &O) -> R

Compute RangeList without any of the elements in the ranges of other. Read more
Source§

fn disjoint<O: IntervalIterator<E> + ?Sized>(&self, other: &O) -> bool

Returns whether self and other are disjoint sets
Source§

fn intersect<O, R>(&self, other: &O) -> R

Return the set intersection of two interval iterators.
Source§

fn subset<O: IntervalIterator<E> + ?Sized>(&self, other: &O) -> bool

Returns whether self is a subset of other
Source§

fn superset<O: IntervalIterator<E> + ?Sized>(&self, other: &O) -> bool

Returns whether self is a superset of other
Source§

fn union<O, R>(&self, other: &O) -> R

Return the set union of two interval iterators.
Source§

impl<'a, E: PartialOrd> IntoIterator for &'a RangeList<E>

Source§

type IntoIter = Map<Iter<'a, (E, E)>, fn(_: &'a (E, E)) -> RangeInclusive<&'a E>>

Which kind of iterator are we turning this into?
Source§

type Item = RangeInclusive<&'a E>

The type of the elements being iterated over.
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<E: PartialOrd + Clone> IntoIterator for RangeList<E>

Source§

type IntoIter = Map<IntoIter<(E, E)>, fn(_: (E, E)) -> RangeInclusive<E>>

Which kind of iterator are we turning this into?
Source§

type Item = RangeInclusive<E>

The type of the elements being iterated over.
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<E: PartialEq + PartialOrd> PartialEq for RangeList<E>

Source§

fn eq(&self, other: &RangeList<E>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<E: PartialOrd + PartialOrd> PartialOrd for RangeList<E>

Source§

fn partial_cmp(&self, other: &RangeList<E>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<E: Eq + PartialOrd> Eq for RangeList<E>

Source§

impl<E: PartialOrd> StructuralPartialEq for RangeList<E>

Auto Trait Implementations§

§

impl<E> Freeze for RangeList<E>

§

impl<E> RefUnwindSafe for RangeList<E>
where E: RefUnwindSafe,

§

impl<E> Send for RangeList<E>
where E: Send,

§

impl<E> Sync for RangeList<E>
where E: Sync,

§

impl<E> Unpin for RangeList<E>
where E: Unpin,

§

impl<E> UnwindSafe for RangeList<E>
where E: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.