Struct nodit::interval::Interval

source ·
pub struct Interval<I> { /* private fields */ }
Expand description

An inclusive interval, only valid intervals can be constructed.

This interval struct is used throughout this crate for the examples and tests but can also be used by library users if they don’t wish to create their own interval types.

To create an InclusiveInterval use one of the various contrutor functions which will all panic if you try to create an invalid interval. See Invalid Intervals for more details.

use nodit::interval::{ee, ii};

let inclusive_interval = ii(4, 4);
let exclusive_interval = ee(3, 5);

assert_eq!(inclusive_interval, exclusive_interval);
use nodit::interval::ee;

let invalid_interval = ee(4, 4);

Implementations§

source§

impl<I> Interval<I>
where I: PointType,

source

pub fn start(&self) -> I

The start of the interval, inclusive.

use nodit::interval::ii;

assert_eq!(ii(2, 4).start(), 2);
source

pub fn end(&self) -> I

The end of the interval, inclusive.

use nodit::interval::ii;

assert_eq!(ii(2, 4).end(), 4);

Trait Implementations§

source§

impl<I: Clone> Clone for Interval<I>

source§

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

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<I: Debug> Debug for Interval<I>

source§

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

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

impl<'de, I> Deserialize<'de> for Interval<I>
where I: Deserialize<'de>,

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<I> From<Interval<I>> for Range<I>
where I: PointType,

source§

fn from(value: Interval<I>) -> Self

Converts to this type from the input type.
source§

impl<I> From<Interval<I>> for RangeInclusive<I>

source§

fn from(value: Interval<I>) -> Self

Converts to this type from the input type.
source§

impl<I> From<Range<I>> for Interval<I>
where I: PointType,

source§

fn from(value: Range<I>) -> Self

Converts to this type from the input type.
source§

impl<I> From<RangeInclusive<I>> for Interval<I>
where I: PointType,

source§

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

Converts to this type from the input type.
source§

impl<I: Hash> Hash for Interval<I>

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<I> InclusiveInterval<I> for Interval<I>
where I: PointType,

source§

fn start(&self) -> I

The start of the interval, inclusive.
source§

fn end(&self) -> I

The end of the interval, inclusive.
source§

fn contains(&self, point: I) -> bool
where I: PointType,

Does the interval contain the given point?
source§

fn is_valid(&self) -> bool
where I: PointType,

Is the interval is valid, which according to this crate means start() <= end()
source§

fn touches_ordered(&self, other: &Self) -> bool
where I: PointType,

Requires that self comes before other and they don’t overlap
source§

fn overlaps_ordered(&self, other: &Self) -> bool
where I: PointType,

Requires that self comes before other
source§

fn intersect(&self, other: &Self) -> Option<Self>
where I: PointType, Self: From<Interval<I>>,

Intersect the interval with the other one, and return Some if the intersection is not empty.
source§

fn merge_ordered(&self, other: &Self) -> Self
where Self: From<Interval<I>>,

Requires that self comes before other
source§

impl<I: PartialEq> PartialEq for Interval<I>

source§

fn eq(&self, other: &Interval<I>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<I> RangeBounds<I> for Interval<I>
where I: PointType,

source§

fn start_bound(&self) -> Bound<&I>

Start index bound. Read more
source§

fn end_bound(&self) -> Bound<&I>

End index bound. Read more
1.35.0 · source§

fn contains<U>(&self, item: &U) -> bool
where T: PartialOrd<U>, U: PartialOrd<T> + ?Sized,

Returns true if item is contained in the range. Read more
source§

impl<I> Serialize for Interval<I>
where I: Serialize,

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<I: Copy> Copy for Interval<I>

source§

impl<I: Eq> Eq for Interval<I>

source§

impl<I> StructuralEq for Interval<I>

source§

impl<I> StructuralPartialEq for Interval<I>

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

impl<I> UnwindSafe for Interval<I>
where I: 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> 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,

§

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>,

§

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>,

§

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.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

source§

impl<I, K> IntervalType<I> for K
where I: PointType, K: InclusiveInterval<I> + Copy + From<Interval<I>>,