pub struct Interval<T> {
pub lower: Bound<T>,
pub upper: Bound<T>,
}
Expand description
Represents an interval with a lower
and an upper
bound.
The Interval
type allows modeling ranges of values with optional inclusion
or exclusion at each bound. This is useful for mathematical operations,
range checks, and interval arithmetic.
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 $(a, b]$.
Sourcepub const fn open_unbounded(lower: T) -> Self
pub const fn open_unbounded(lower: T) -> Self
Creates an interval $(l, ∞)$.
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: ConstDefault,
pub const fn empty_const() -> Selfwhere
T: ConstDefault,
Creates a canonical empty interval,
equivalent to open
(T::default(), T::default())
.
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: 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
lower
bound is strictly greater than theupper
bound.
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> ConstDefault for Interval<T>
Provides a const default value for Interval
, the unbounded interval $(-\infty, \infty)$.
impl<T> ConstDefault for Interval<T>
Provides a const default value for Interval
, the unbounded interval $(-\infty, \infty)$.
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
Default
forT
, making it applicable to all types. - Aligns with mathematical conventions, where unbounded intervals are a natural default.
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(a) < Excluded(a) at same point a.
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(a) < Excluded(a) at same point a.
Source§impl<T> RangeBounds<T> for Interval<T>
impl<T> RangeBounds<T> for Interval<T>
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 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 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.
impl<T: Copy> Copy for Interval<T>
impl<T: Eq> Eq for Interval<T>
impl<T> StructuralPartialEq for Interval<T>
Auto Trait Implementations§
impl<T> Freeze for Interval<T>where
T: Freeze,
impl<T> RefUnwindSafe for Interval<T>where
T: RefUnwindSafe,
impl<T> Send for Interval<T>where
T: Send,
impl<T> Sync for Interval<T>where
T: Sync,
impl<T> Unpin for Interval<T>where
T: Unpin,
impl<T> UnwindSafe for Interval<T>where
T: UnwindSafe,
Blanket Implementations§
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> ByteSized for T
impl<T> ByteSized for T
Source§const BYTE_ALIGN: usize = _
const BYTE_ALIGN: usize = _
Source§fn byte_align(&self) -> usize ⓘ
fn byte_align(&self) -> usize ⓘ
Source§fn ptr_size_ratio(&self) -> [usize; 2]
fn ptr_size_ratio(&self) -> [usize; 2]
Source§impl<T, R> Chain<R> for Twhere
T: ?Sized,
impl<T, R> Chain<R> for Twhere
T: ?Sized,
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T> ExtAny for T
impl<T> ExtAny for T
Source§fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
Source§impl<T> ExtMem for Twhere
T: ?Sized,
impl<T> ExtMem for Twhere
T: ?Sized,
Source§const NEEDS_DROP: bool = _
const NEEDS_DROP: bool = _
Source§fn mem_align_of_val(&self) -> usize ⓘ
fn mem_align_of_val(&self) -> usize ⓘ
Source§fn mem_size_of_val(&self) -> usize ⓘ
fn mem_size_of_val(&self) -> usize ⓘ
Source§fn mem_needs_drop(&self) -> bool
fn mem_needs_drop(&self) -> bool
true
if dropping values of this type matters. Read moreSource§fn mem_forget(self)where
Self: Sized,
fn mem_forget(self)where
Self: Sized,
self
without running its destructor. Read moreSource§fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
Source§unsafe fn mem_zeroed<T>() -> T
unsafe fn mem_zeroed<T>() -> T
unsafe_layout
only.T
represented by the all-zero byte-pattern. Read moreSource§unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe_layout
only.T
represented by the all-zero byte-pattern. Read moreSource§fn mem_as_bytes(&self) -> &[u8] ⓘ
fn mem_as_bytes(&self) -> &[u8] ⓘ
unsafe_slice
only.§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Hook for T
impl<T> Hook for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError> ⓘ
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError> ⓘ
§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out
indicating that a T
is niched.