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: 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(l) < Excluded(l) at same point l.
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>
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ยง
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 type_hash_with<H: Hasher>(&self, hasher: H) -> u64
fn type_hash_with<H: Hasher>(&self, hasher: H) -> u64
TypeId
of Self
using a custom hasher.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<T>() -> usize
fn mem_align_of<T>() -> usize
Sourceยงfn mem_align_of_val(&self) -> usize
fn mem_align_of_val(&self) -> usize
Sourceยงfn mem_size_of<T>() -> usize
fn mem_size_of<T>() -> 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
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