pub struct Interval<N: Ord + Clone>(/* private fields */);
Expand description
An Interval
wraps the std::ops::Range
from the stdlib and is defined by a start and end field
where end should be >= start.
Implementations§
Methods from Deref<Target = Range<N>>§
1.35.0 · sourcepub fn contains<U>(&self, item: &U) -> bool
pub fn contains<U>(&self, item: &U) -> bool
Returns true
if item
is contained in the range.
§Examples
assert!(!(3..5).contains(&2));
assert!( (3..5).contains(&3));
assert!( (3..5).contains(&4));
assert!(!(3..5).contains(&5));
assert!(!(3..3).contains(&3));
assert!(!(3..2).contains(&3));
assert!( (0.0..1.0).contains(&0.5));
assert!(!(0.0..1.0).contains(&f32::NAN));
assert!(!(0.0..f32::NAN).contains(&0.5));
assert!(!(f32::NAN..1.0).contains(&0.5));
1.47.0 · sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true
if the range contains no items.
§Examples
assert!(!(3..5).is_empty());
assert!( (3..3).is_empty());
assert!( (3..2).is_empty());
The range is empty if either side is incomparable:
assert!(!(3.0..5.0).is_empty());
assert!( (3.0..f32::NAN).is_empty());
assert!( (f32::NAN..5.0).is_empty());
Trait Implementations§
source§impl<'de, N> Deserialize<'de> for Interval<N>
impl<'de, N> Deserialize<'de> for Interval<N>
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
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<'a, N: Ord + Clone> From<&'a Range<N>> for Interval<N>
impl<'a, N: Ord + Clone> From<&'a Range<N>> for Interval<N>
Convert a reference to a Range
to an interval by cloning. This conversion will panic if the
Range
has end < start
source§impl<N: Ord + Clone> From<Range<N>> for Interval<N>
impl<N: Ord + Clone> From<Range<N>> for Interval<N>
Convert a Range
into an Interval
. This conversion will panic if the Range
has end < start
source§impl<N: PartialEq + Ord + Clone> PartialEq for Interval<N>
impl<N: PartialEq + Ord + Clone> PartialEq for Interval<N>
source§impl<N: Ord + Clone> Deref for Interval<N>
impl<N: Ord + Clone> Deref for Interval<N>
Use the Deref
operator to get a reference to Range
wrapped by the Interval
newtype.
impl<N: Eq + Ord + Clone> Eq for Interval<N>
impl<N: Ord + Clone> StructuralPartialEq for Interval<N>
Auto Trait Implementations§
impl<N> Freeze for Interval<N>where
N: Freeze,
impl<N> RefUnwindSafe for Interval<N>where
N: RefUnwindSafe,
impl<N> Send for Interval<N>where
N: Send,
impl<N> Sync for Interval<N>where
N: Sync,
impl<N> Unpin for Interval<N>where
N: Unpin,
impl<N> UnwindSafe for Interval<N>where
N: 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
Mutably borrows from an owned value. Read more
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self
from the equivalent element of its
superset. Read moresource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self
is actually part of its subset T
(and can be converted to it).source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset
but without any property checks. Always succeeds.source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self
to the equivalent element of its superset.