pub struct Interval<T> {
pub lower: Bound<T>,
pub upper: Bound<T>,
}Expand description
Fieldsยง
ยงlower: Bound<T>The lower bound (also known as the start bound, or the left bound).
upper: Bound<T>The upper bound (also known as the end, bound or the right bound).
Implementationsยง
Sourceยงimpl<T> Interval<T>
ยงMethodical constructors
impl<T> Interval<T>
ยงMethodical constructors
Sourcepub const fn closed(lower: T, upper: T) -> Self
pub const fn closed(lower: T, upper: T) -> Self
Creates a closed interval $[l, u]$ lower..=upper RangeInclusive.
Sourcepub const fn closed_open(lower: T, upper: T) -> Self
pub const fn closed_open(lower: T, upper: T) -> Self
Creates a half-open interval $[l, u)$ lower..upper Range.
Sourcepub const fn closed_unbounded(lower: T) -> Self
pub const fn closed_unbounded(lower: T) -> Self
Creates an interval $[l, โ)$ lower.. RangeFrom.
Sourcepub const fn open_closed(lower: T, upper: T) -> Self
pub const fn open_closed(lower: T, upper: T) -> Self
Creates a half-open interval $(l, u]$ lower..<=upper.
Sourcepub const fn open_unbounded(lower: T) -> Self
pub const fn open_unbounded(lower: T) -> Self
Creates an interval $(l, โ)$ lower..<.
Sourcepub const fn unbounded_closed(upper: T) -> Self
pub const fn unbounded_closed(upper: T) -> Self
Creates an interval $(-โ, u]$ ..upper RangeTo.
Sourcepub const fn unbounded_open(upper: T) -> Self
pub const fn unbounded_open(upper: T) -> Self
Creates an interval $(-โ, u)$ ..=upper RangeToInclusive.
Sourceยงimpl<T> Interval<T>
ยงAdditional constructors
impl<T> Interval<T>
ยงAdditional constructors
Sourcepub const fn new(lower: Bound<T>, upper: Bound<T>) -> Self
pub const fn new(lower: Bound<T>, upper: Bound<T>) -> Self
Creates a new interval with the given lower and upper bounds.
Sourcepub fn point(value: T) -> Selfwhere
T: Clone,
pub fn point(value: T) -> Selfwhere
T: Clone,
Creates a single-point interval,
equivalent to closed(value, value).
Sourcepub fn empty() -> Selfwhere
T: Default,
pub fn empty() -> Selfwhere
T: Default,
Creates a canonical empty interval,
equivalent to open(T::default(), T::default()).
Sourcepub const fn empty_const() -> Selfwhere
T: ConstInitCore,
pub const fn empty_const() -> Selfwhere
T: ConstInitCore,
Creates a canonical empty interval,
equivalent to open(T::INIT, T::INIT).
Sourcepub fn empty_with(value: T) -> Selfwhere
T: Clone,
pub fn empty_with(value: T) -> Selfwhere
T: Clone,
Creates a canonical empty interval,
equivalent to open(value, value).
Sourceยงimpl<T> Interval<T>
impl<T> Interval<T>
Sourcepub fn into_tuple(self) -> (Bound<T>, Bound<T>) โ
pub fn into_tuple(self) -> (Bound<T>, Bound<T>) โ
Returns both bounds as a tuple (lower, upper).
Sourcepub fn to_tuple_ref(&self) -> (Bound<&T>, Bound<&T>) โ
pub fn to_tuple_ref(&self) -> (Bound<&T>, Bound<&T>) โ
Returns a reference to both bounds as a tuple (&lower, &upper).
Sourcepub const fn is_bounded(&self) -> bool
pub const fn is_bounded(&self) -> bool
Checks if the interval is both lower and upper bounded.
Sourcepub const fn is_lower_bounded(&self) -> bool
pub const fn is_lower_bounded(&self) -> bool
Checks if the lower bound is bounded.
Sourcepub const fn is_upper_bounded(&self) -> bool
pub const fn is_upper_bounded(&self) -> bool
Checks if the upper bound is bounded.
Sourcepub const fn is_lower_open(&self) -> bool
pub const fn is_lower_open(&self) -> bool
Checks if the lower bound is open (excluded).
Sourcepub const fn is_lower_closed(&self) -> bool
pub const fn is_lower_closed(&self) -> bool
Checks if the lower bound is closed (included).
Sourcepub const fn is_upper_open(&self) -> bool
pub const fn is_upper_open(&self) -> bool
Checks if the upper bound is open (excluded).
Sourcepub const fn is_upper_closed(&self) -> bool
pub const fn is_upper_closed(&self) -> bool
Checks if the upper bound is closed (included).
Sourceยงimpl<T> Interval<T>
impl<T> Interval<T>
Sourcepub const fn bound(&self, side: Boundary1d) -> &Bound<T>
pub const fn bound(&self, side: Boundary1d) -> &Bound<T>
Returns the bound corresponding to the given boundary orientation.
Sourcepub fn bound_mut(&mut self, side: Boundary1d) -> &mut Bound<T>
pub fn bound_mut(&mut self, side: Boundary1d) -> &mut Bound<T>
Returns a mutable reference to the bound corresponding to the given boundary orientation.
Sourcepub fn bound_as_ref(&self, side: Boundary1d) -> Bound<&T>
pub fn bound_as_ref(&self, side: Boundary1d) -> Bound<&T>
Returns the bound corresponding to the given boundary, with the contained value borrowed.
Sourceยงimpl<T: PartialOrd> Interval<T>
impl<T: PartialOrd> Interval<T>
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Checks if the interval is empty (contains no values).
An interval is empty if:
- The bounds exclude each other, such as
(x, x),[x, x), or(x, x]. - The
lowerbound is strictly greater than theupperbound.
Unbounded intervals are never empty.
Sourcepub fn is_well_ordered(&self) -> bool
pub fn is_well_ordered(&self) -> bool
Validates that the interval bounds are ordered correctly.
Returns true if the lower bound is less than or equal to the upper bound.
Unbounded intervals are always considered well ordered.
Trait Implementationsยง
Sourceยงimpl<T> ConstInitCore for Interval<T>
Provides a const default value for Interval, the unbounded interval $(-\infty, \infty)$.
impl<T> ConstInitCore for Interval<T>
Provides a const default value for Interval, the unbounded interval $(-\infty, \infty)$.
See the default implementation for more information.
impl<T: Copy> Copy for Interval<T>
Sourceยงimpl<T> Default for Interval<T>
Provides a default value for Interval, the unbounded interval $(-\infty, \infty)$.
impl<T> Default for Interval<T>
Provides a default value for Interval, the unbounded interval $(-\infty, \infty)$.
This choice emphasizes neutrality and generality,
where the interval encompasses all possible values of T. It:
- Represents a neutral and maximal range for generic use cases.
- Avoids reliance on
DefaultforT, making it applicable to all types. - Aligns with mathematical conventions, where unbounded intervals are a natural default.
impl<T: Eq> Eq for Interval<T>
Sourceยงimpl<T> From<RangeInclusive<T>> for Interval<T>
impl<T> From<RangeInclusive<T>> for Interval<T>
Sourceยงfn from(r: RangeInclusive<T>) -> Self
fn from(r: RangeInclusive<T>) -> Self
Sourceยงimpl<T> From<RangeToInclusive<T>> for Interval<T>
impl<T> From<RangeToInclusive<T>> for Interval<T>
Sourceยงfn from(r: RangeToInclusive<T>) -> Self
fn from(r: RangeToInclusive<T>) -> Self
Sourceยงimpl<T: Ord> Ord for Interval<T>
Comparison Logic:
impl<T: Ord> Ord for Interval<T>
Comparison Logic:
- We compare the lower bounds first.
- If the lower bounds are equal, we compare the upper bounds.
- We define Unbounded as less than any bounded value.
- We define that Included(l) < Excluded(l) at same point l.
1.21.0 (const: unstable) ยท Sourceยงfn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) ยท Sourceยงfn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Sourceยงimpl<T: PartialOrd> PartialOrd for Interval<T>
Comparison Logic:
impl<T: PartialOrd> PartialOrd for Interval<T>
Comparison Logic:
- We compare the lower bounds first.
- If the lower bounds are equal, we compare the upper bounds.
- We define Unbounded as less than any bounded value.
- We define that Included(l) < Excluded(l) at same point l.
Sourceยงimpl<T> RangeBounds<T> for Interval<T>
impl<T> RangeBounds<T> for Interval<T>
impl<T: PartialEq> StructuralPartialEq for Interval<T>
Sourceยงimpl<T> TryFrom<Interval<T>> for RangeInclusive<T>
ยงErrors
Returns IncompatibleBounds if the bounds are not compatible.
impl<T> TryFrom<Interval<T>> for RangeInclusive<T>
ยงErrors
Returns IncompatibleBounds if the bounds are not compatible.
Sourceยงimpl<T> TryFrom<Interval<T>> for Range<T>
ยงErrors
Returns IncompatibleBounds if the bounds are not compatible.
impl<T> TryFrom<Interval<T>> for Range<T>
ยงErrors
Returns IncompatibleBounds if the bounds are not compatible.
Sourceยงimpl<T> TryFrom<Interval<T>> for RangeFrom<T>
ยงErrors
Returns IncompatibleBounds if the bounds are not compatible.
impl<T> TryFrom<Interval<T>> for RangeFrom<T>
ยงErrors
Returns IncompatibleBounds if the bounds are not compatible.
Sourceยงimpl<T> TryFrom<Interval<T>> for RangeFull
ยงErrors
Returns IncompatibleBounds if the bounds are not compatible.
impl<T> TryFrom<Interval<T>> for RangeFull
ยงErrors
Returns IncompatibleBounds if the bounds are not compatible.
Sourceยงimpl<T> TryFrom<Interval<T>> for RangeTo<T>
ยงErrors
Returns IncompatibleBounds if the bounds are not compatible.
impl<T> TryFrom<Interval<T>> for RangeTo<T>
ยงErrors
Returns IncompatibleBounds if the bounds are not compatible.
Sourceยงimpl<T> TryFrom<Interval<T>> for RangeToInclusive<T>
ยงErrors
Returns IncompatibleBounds if the bounds are not compatible.
impl<T> TryFrom<Interval<T>> for RangeToInclusive<T>
ยงErrors
Returns IncompatibleBounds if the bounds are not compatible.