Interval

Struct Interval 

Source
pub struct Interval<Ix> {
    pub start: Ix,
    pub end: Ix,
}
Expand description

A half-open interval [start, end).

This is a helper struct used internally for interval operations. Intervals are represented as half-open ranges matching Rust’s Range<T>.

Fields§

§start: Ix

The inclusive start of the interval.

§end: Ix

The exclusive end of the interval.

Implementations§

Source§

impl<Ix: IndexType> Interval<Ix>

Source

pub fn new(start: Ix, end: Ix) -> Self

Creates a new interval [start, end).

§Panics

Panics if start > end.

Source

pub fn is_empty(&self) -> bool

Returns true if this interval is empty (start == end).

Source

pub fn contains_point(&self, point: Ix) -> bool

Returns true if this interval contains the given point.

A point p is contained if start <= p < end.

Source

pub fn overlaps(&self, other: &Interval<Ix>) -> bool

Returns true if this interval overlaps with another.

Two intervals overlap if they share at least one point.

Source

pub fn touches(&self, other: &Interval<Ix>) -> bool

Returns true if this interval touches another (adjacent or overlapping).

Two intervals touch if they are adjacent (one’s end equals other’s start) or if they overlap.

Source

pub fn to_range(&self) -> Range<Ix>

Converts this interval to a Range<Ix>.

Trait Implementations§

Source§

impl<Ix: Clone> Clone for Interval<Ix>

Source§

fn clone(&self) -> Interval<Ix>

Returns a duplicate 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<Ix: Debug> Debug for Interval<Ix>

Source§

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

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

impl<Ix: IndexType> From<Interval<Ix>> for Range<Ix>

Source§

fn from(interval: Interval<Ix>) -> Self

Converts to this type from the input type.
Source§

impl<Ix: IndexType> From<Range<Ix>> for Interval<Ix>

Source§

fn from(range: Range<Ix>) -> Self

Converts to this type from the input type.
Source§

impl<Ix: IndexType> From<RangeFrom<Ix>> for Interval<Ix>

Source§

fn from(range: RangeFrom<Ix>) -> Self

Converts an unbounded-end range a.. to interval [a, MAX).

Source§

impl<Ix: IndexType> From<RangeFull> for Interval<Ix>

Source§

fn from(_: RangeFull) -> Self

Converts a full range .. to interval [MIN, MAX).

Source§

impl<Ix: IndexType> From<RangeInclusive<Ix>> for Interval<Ix>

Source§

fn from(range: RangeInclusive<Ix>) -> Self

Converts an inclusive range a..=b to a half-open interval [a, b+1).

§Panics

Panics if b == Ix::MAX since b + 1 would overflow.

Source§

impl<Ix: IndexType> From<RangeTo<Ix>> for Interval<Ix>

Source§

fn from(range: RangeTo<Ix>) -> Self

Converts an unbounded-start range ..b to interval [MIN, b).

Source§

impl<Ix: PartialEq> PartialEq for Interval<Ix>

Source§

fn eq(&self, other: &Interval<Ix>) -> 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<Ix: Copy> Copy for Interval<Ix>

Source§

impl<Ix: Eq> Eq for Interval<Ix>

Source§

impl<Ix> StructuralPartialEq for Interval<Ix>

Auto Trait Implementations§

§

impl<Ix> Freeze for Interval<Ix>
where Ix: Freeze,

§

impl<Ix> RefUnwindSafe for Interval<Ix>
where Ix: RefUnwindSafe,

§

impl<Ix> Send for Interval<Ix>
where Ix: Send,

§

impl<Ix> Sync for Interval<Ix>
where Ix: Sync,

§

impl<Ix> Unpin for Interval<Ix>
where Ix: Unpin,

§

impl<Ix> UnwindSafe for Interval<Ix>
where Ix: 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.