Struct BoundedRange

Source
pub struct BoundedRange<T> {
    pub start: LowerBound<T>,
    pub end: UpperBound<T>,
}
Expand description

A range bounded both below and above (either inclusive or exclusive).

Generalizes over std::ops::Range and std::ops::RangeInclusive but also supports ranges with an exclusive lower bound.

While a BoundedRange can be constructed from one of the above types, it will most likely result from one or more range operations.

use rangetools::{BoundedRange, LowerBound, Rangetools, UpperBound};

let i = (0..5).intersection(3..7);
assert_eq!(i, BoundedRange { start: LowerBound::included(3), end: UpperBound::excluded(5) });

The range is empty if the start bound is greater than the end bound. Note that a range with start bound Bound::Excluded(3) and end bound Bound::Excluded(4) is not considered empty even though it doesn’t contain any values.

Fields§

§start: LowerBound<T>

The lower bound of the range (can be inclusive or exclusive).

§end: UpperBound<T>

The upper bound of the range (can be inclusive or exclusive).

Implementations§

Source§

impl<T: Copy + Ord> BoundedRange<T>

Source

pub fn new(start: LowerBound<T>, end: UpperBound<T>) -> Self

Constructs a new BoundedRange from a lower bound and an upper bound.

§Example
use rangetools::{BoundedRange, LowerBound, UpperBound};

let r = BoundedRange::new(LowerBound::included(0), UpperBound::included(10));
assert!(r.contains(5));
Source

pub fn contains(&self, t: T) -> bool

Returns true if the range contains t.

§Example
use rangetools::Rangetools;

let r = (1..10).intersection(5..7);
assert!(r.contains(5));
assert!(!r.contains(3));

Trait Implementations§

Source§

impl<T: Clone> Clone for BoundedRange<T>

Source§

fn clone(&self) -> BoundedRange<T>

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

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

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for BoundedRange<T>

Source§

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

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

impl<T: Copy + Ord> From<BoundedRange<T>> for BoundedSet<T>

Source§

fn from(r: BoundedRange<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<BoundedRange<T>> for Range<T>
where T: Copy + Step,

Source§

fn from(r: BoundedRange<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<BoundedRange<T>> for RangeInclusive<T>
where T: Copy + Step,

Source§

fn from(r: BoundedRange<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Range<T>> for BoundedRange<T>

Source§

fn from(r: Range<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<RangeInclusive<T>> for BoundedRange<T>

Source§

fn from(r: RangeInclusive<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: Hash> Hash for BoundedRange<T>

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<T> Index<BoundedRange<usize>> for [T]

Source§

type Output = [T]

The returned type after indexing.
Source§

fn index(&self, r: BoundedRange<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<BoundedRange<usize>> for String

Source§

type Output = str

The returned type after indexing.
Source§

fn index(&self, r: BoundedRange<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<T> Index<BoundedRange<usize>> for Vec<T>

Source§

type Output = [T]

The returned type after indexing.
Source§

fn index(&self, r: BoundedRange<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<BoundedRange<usize>> for str

Source§

type Output = str

The returned type after indexing.
Source§

fn index(&self, r: BoundedRange<usize>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<T> IndexMut<BoundedRange<usize>> for [T]

Source§

fn index_mut(&mut self, r: BoundedRange<usize>) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl IndexMut<BoundedRange<usize>> for String

Source§

fn index_mut(&mut self, r: BoundedRange<usize>) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<T> IndexMut<BoundedRange<usize>> for Vec<T>

Source§

fn index_mut(&mut self, r: BoundedRange<usize>) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl IndexMut<BoundedRange<usize>> for str

Source§

fn index_mut(&mut self, r: BoundedRange<usize>) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<T> IntoIterator for BoundedRange<T>
where T: Copy + Ord + Step,

Source§

type IntoIter = BoundedRangeIter<T>

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

type Item = T

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<T: PartialEq> PartialEq for BoundedRange<T>

Source§

fn eq(&self, other: &BoundedRange<T>) -> bool

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

const 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<T> RangeComplement<UnboundedSet<T>> for BoundedRange<T>
where T: Copy + Ord,

Source§

fn complement(self) -> UnboundedSet<T>

Returns a set of all the elements not in self.
Source§

impl<T, R> RangeIntersection<R, BoundedRange<T>> for BoundedRange<T>
where R: Rangetools<Inner = BoundedRange<T>>, T: Copy + Ord,

Source§

type Output = BoundedRange<T>

The output type of the intersection.
Source§

fn intersection(self, other: R) -> Self::Output

Returns the set intersection of self and other.
Source§

impl<T, R> RangeIntersection<R, BoundedRange<T>> for BoundedSet<T>
where R: Rangetools<Inner = BoundedRange<T>>, T: Copy + Ord,

Source§

type Output = BoundedSet<T>

The output type of the intersection.
Source§

fn intersection(self, other: R) -> Self::Output

Returns the set intersection of self and other.
Source§

impl<T, R> RangeIntersection<R, BoundedRange<T>> for LowerBoundedRange<T>
where R: Rangetools<Inner = BoundedRange<T>>, T: Copy + Ord,

Source§

type Output = BoundedRange<T>

The output type of the intersection.
Source§

fn intersection(self, other: R) -> Self::Output

Returns the set intersection of self and other.
Source§

impl<T, R> RangeIntersection<R, BoundedRange<T>> for LowerBoundedSet<T>
where R: Rangetools<Inner = BoundedRange<T>>, T: Copy + Ord,

Source§

type Output = BoundedSet<T>

The output type of the intersection.
Source§

fn intersection(self, other: R) -> Self::Output

Returns the set intersection of self and other.
Source§

impl<T, R> RangeIntersection<R, BoundedRange<T>> for Range<T>
where R: Rangetools<Inner = BoundedRange<T>>, T: Copy + Ord,

Source§

type Output = BoundedRange<T>

The output type of the intersection.
Source§

fn intersection(self, other: R) -> Self::Output

Returns the set intersection of self and other.
Source§

impl<T, R> RangeIntersection<R, BoundedRange<T>> for RangeFrom<T>
where R: Rangetools<Inner = BoundedRange<T>>, T: Copy + Ord,

Source§

type Output = BoundedRange<T>

The output type of the intersection.
Source§

fn intersection(self, other: R) -> Self::Output

Returns the set intersection of self and other.
Source§

impl<T, R> RangeIntersection<R, BoundedRange<T>> for RangeFull
where R: Rangetools<Inner = BoundedRange<T>>,

Source§

type Output = BoundedRange<T>

The output type of the intersection.
Source§

fn intersection(self, other: R) -> Self::Output

Returns the set intersection of self and other.
Source§

impl<T, R> RangeIntersection<R, BoundedRange<T>> for RangeInclusive<T>
where R: Rangetools<Inner = BoundedRange<T>>, T: Copy + Ord,

Source§

type Output = BoundedRange<T>

The output type of the intersection.
Source§

fn intersection(self, other: R) -> Self::Output

Returns the set intersection of self and other.
Source§

impl<T, R> RangeIntersection<R, BoundedRange<T>> for RangeTo<T>
where R: Rangetools<Inner = BoundedRange<T>>, T: Copy + Ord,

Source§

type Output = BoundedRange<T>

The output type of the intersection.
Source§

fn intersection(self, other: R) -> Self::Output

Returns the set intersection of self and other.
Source§

impl<T, R> RangeIntersection<R, BoundedRange<T>> for RangeToInclusive<T>
where R: Rangetools<Inner = BoundedRange<T>>, T: Copy + Ord,

Source§

type Output = BoundedRange<T>

The output type of the intersection.
Source§

fn intersection(self, other: R) -> Self::Output

Returns the set intersection of self and other.
Source§

impl<T, R> RangeIntersection<R, BoundedRange<T>> for UnboundedSet<T>
where R: Rangetools<Inner = BoundedRange<T>>, T: Copy + Ord,

Source§

type Output = BoundedSet<T>

The output type of the intersection.
Source§

fn intersection(self, other: R) -> Self::Output

Returns the set intersection of self and other.
Source§

impl<T, R> RangeIntersection<R, BoundedRange<T>> for UpperBoundedRange<T>
where R: Rangetools<Inner = BoundedRange<T>>, T: Copy + Ord,

Source§

type Output = BoundedRange<T>

The output type of the intersection.
Source§

fn intersection(self, other: R) -> Self::Output

Returns the set intersection of self and other.
Source§

impl<T, R> RangeIntersection<R, BoundedRange<T>> for UpperBoundedSet<T>
where R: Rangetools<Inner = BoundedRange<T>>, T: Copy + Ord,

Source§

type Output = BoundedSet<T>

The output type of the intersection.
Source§

fn intersection(self, other: R) -> Self::Output

Returns the set intersection of self and other.
Source§

impl<T, R> RangeIntersection<R, BoundedSet<T>> for BoundedRange<T>
where R: Rangetools<Inner = BoundedSet<T>>, T: Copy + Ord,

Source§

type Output = BoundedSet<T>

The output type of the intersection.
Source§

fn intersection(self, other: R) -> Self::Output

Returns the set intersection of self and other.
Source§

impl<T, R> RangeIntersection<R, EmptyRange<T>> for BoundedRange<T>
where R: Rangetools<Inner = EmptyRange<T>>, T: Copy + Ord,

Source§

type Output = EmptyRange<T>

The output type of the intersection.
Source§

fn intersection(self, other: R) -> Self::Output

Returns the set intersection of self and other.
Source§

impl<T, R> RangeIntersection<R, LowerBoundedRange<T>> for BoundedRange<T>
where R: Rangetools<Inner = LowerBoundedRange<T>>, T: Copy + Ord,

Source§

type Output = BoundedRange<T>

The output type of the intersection.
Source§

fn intersection(self, other: R) -> Self::Output

Returns the set intersection of self and other.
Source§

impl<T, R> RangeIntersection<R, LowerBoundedSet<T>> for BoundedRange<T>
where R: Rangetools<Inner = LowerBoundedSet<T>>, T: Copy + Ord,

Source§

type Output = BoundedSet<T>

The output type of the intersection.
Source§

fn intersection(self, other: R) -> Self::Output

Returns the set intersection of self and other.
Source§

impl<T, R> RangeIntersection<R, UnboundedRange> for BoundedRange<T>
where R: Rangetools<Inner = UnboundedRange>, T: Copy + Ord,

Source§

type Output = BoundedRange<T>

The output type of the intersection.
Source§

fn intersection(self, other: R) -> Self::Output

Returns the set intersection of self and other.
Source§

impl<T, R> RangeIntersection<R, UnboundedSet<T>> for BoundedRange<T>
where R: Rangetools<Inner = UnboundedSet<T>>, T: Copy + Ord,

Source§

type Output = BoundedSet<T>

The output type of the intersection.
Source§

fn intersection(self, other: R) -> Self::Output

Returns the set intersection of self and other.
Source§

impl<T, R> RangeIntersection<R, UpperBoundedRange<T>> for BoundedRange<T>
where R: Rangetools<Inner = UpperBoundedRange<T>>, T: Copy + Ord,

Source§

type Output = BoundedRange<T>

The output type of the intersection.
Source§

fn intersection(self, other: R) -> Self::Output

Returns the set intersection of self and other.
Source§

impl<T, R> RangeIntersection<R, UpperBoundedSet<T>> for BoundedRange<T>
where R: Rangetools<Inner = UpperBoundedSet<T>>, T: Copy + Ord,

Source§

type Output = BoundedSet<T>

The output type of the intersection.
Source§

fn intersection(self, other: R) -> Self::Output

Returns the set intersection of self and other.
Source§

impl<T, R> RangeUnion<R, BoundedSet<T>> for BoundedRange<T>
where R: Rangetools<Set = BoundedSet<T>>, T: Copy + Ord,

Source§

type Output = BoundedSet<T>

The output type of the union.
Source§

fn union(self, other: R) -> Self::Output

Returns the set union of self and other.
Source§

impl<T, R> RangeUnion<R, EmptyRange<T>> for BoundedRange<T>
where R: Rangetools<Set = EmptyRange<T>>, T: Copy + Ord,

Source§

type Output = BoundedRange<T>

The output type of the union.
Source§

fn union(self, other: R) -> Self::Output

Returns the set union of self and other.
Source§

impl<T, R> RangeUnion<R, LowerBoundedSet<T>> for BoundedRange<T>
where R: Rangetools<Set = LowerBoundedSet<T>>, T: Copy + Ord,

Source§

type Output = LowerBoundedSet<T>

The output type of the union.
Source§

fn union(self, other: R) -> Self::Output

Returns the set union of self and other.
Source§

impl<T, R> RangeUnion<R, UnboundedRange> for BoundedRange<T>
where R: Rangetools<Set = UnboundedRange>, T: Copy + Ord,

Source§

type Output = UnboundedRange

The output type of the union.
Source§

fn union(self, other: R) -> Self::Output

Returns the set union of self and other.
Source§

impl<T, R> RangeUnion<R, UnboundedSet<T>> for BoundedRange<T>
where R: Rangetools<Set = UnboundedSet<T>>, T: Copy + Ord,

Source§

type Output = UnboundedSet<T>

The output type of the union.
Source§

fn union(self, other: R) -> Self::Output

Returns the set union of self and other.
Source§

impl<T, R> RangeUnion<R, UpperBoundedSet<T>> for BoundedRange<T>
where R: Rangetools<Set = UpperBoundedSet<T>>, T: Copy + Ord,

Source§

type Output = UpperBoundedSet<T>

The output type of the union.
Source§

fn union(self, other: R) -> Self::Output

Returns the set union of self and other.
Source§

impl<T: Copy + Ord> Rangetools for BoundedRange<T>

Source§

type Inner = BoundedRange<T>

The generalized type of the range (for consolidating range types that only differ in whether their bounds are inclusive or exclusive). Read more
Source§

type Set = BoundedSet<T>

The set type of the range, for talking about non-contiguous collections of elements. Read more
Source§

fn is_empty(&self) -> bool

Returns true if the range is empty. Read more
Source§

fn to_inner(self) -> Self::Inner

Convert the range to its inner type. Read more
Source§

fn to_set(self) -> Self::Set

Convert the range to its set type. Read more
Source§

fn complement<Output>(self) -> Output
where Self: Sized + RangeComplement<Output>,

Returns the complement of self (ie, the set of all elements not in self). Read more
Source§

fn intersection<R, Output>(self, other: R) -> Output
where R: Rangetools, Self: Sized + RangeIntersection<R, R::Inner, Output = Output>,

Performs set intersection on self and other. Read more
Source§

fn disjoint<R, Output>(self, other: R) -> bool
where R: Rangetools, Output: Rangetools, Self: Sized + RangeIntersection<R, R::Inner, Output = Output>,

Returns true if two sets/ranges are disjoint (they have no elements in common). Read more
Source§

fn intersects<R, Output>(self, other: R) -> bool
where R: Rangetools, Output: Rangetools, Self: Sized + RangeIntersection<R, R::Inner, Output = Output>,

Returns true if two sets/ranges intersect (they have at least one element in common). Read more
Source§

fn union<R, Output>(self, other: R) -> Output
where R: Rangetools, Self: Sized + RangeUnion<R, R::Set, Output = Output>,

Performs set union on self and other. Read more
Source§

impl<T: Copy> Copy for BoundedRange<T>

Source§

impl<T: Eq> Eq for BoundedRange<T>

Source§

impl<T> StructuralPartialEq for BoundedRange<T>

Auto Trait Implementations§

§

impl<T> Freeze for BoundedRange<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for BoundedRange<T>
where T: RefUnwindSafe,

§

impl<T> Send for BoundedRange<T>
where T: Send,

§

impl<T> Sync for BoundedRange<T>
where T: Sync,

§

impl<T> Unpin for BoundedRange<T>
where T: Unpin,

§

impl<T> UnwindSafe for BoundedRange<T>
where T: 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, 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.