pub struct Range<Idx> {
pub start: Idx,
pub end: RangeEnd<Idx>,
}Expand description
A range bounded on both ends, with an inclusive start and an end whose
inclusivity is recorded by RangeEnd.
Ordering is lexicographic: by start first, then by end.
§Examples
use ps_range::Range;
assert_eq!(Range::from(2..7), Range::exclusive(2, 7));
assert_ne!(Range::inclusive(2, 6), Range::exclusive(2, 7));Fields§
§start: IdxThe inclusive lower bound.
end: RangeEnd<Idx>The upper bound, either inclusive or exclusive.
Implementations§
Trait Implementations§
impl<Idx: Copy> Copy for Range<Idx>
impl<Idx: Eq> Eq for Range<Idx>
Source§impl<Idx> From<Range<Idx>> for PartialRange<Idx>
impl<Idx> From<Range<Idx>> for PartialRange<Idx>
Source§impl<Idx: Clone + PartialOrd> From<RangeInclusive<Idx>> for Range<Idx>
Converts the range, canonicalizing an empty source to an empty exclusive
range at its start. The endpoint values of a drained
std::ops::RangeInclusive are unspecified, so the position of the
resulting empty range is likewise unspecified; only emptiness is
guaranteed.
impl<Idx: Clone + PartialOrd> From<RangeInclusive<Idx>> for Range<Idx>
Converts the range, canonicalizing an empty source to an empty exclusive
range at its start. The endpoint values of a drained
std::ops::RangeInclusive are unspecified, so the position of the
resulting empty range is likewise unspecified; only emptiness is
guaranteed.
Source§fn from(value: RangeInclusive<Idx>) -> Self
fn from(value: RangeInclusive<Idx>) -> Self
Converts to this type from the input type.
Source§impl<Idx> IntoIterator for Range<Idx>
impl<Idx> IntoIterator for Range<Idx>
Source§impl<Idx: Ord> Ord for Range<Idx>
impl<Idx: Ord> Ord for Range<Idx>
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl<Idx: PartialOrd> PartialOrd for Range<Idx>
impl<Idx: PartialOrd> PartialOrd for Range<Idx>
Source§impl<Idx: Clone + Ord> PartialRangeExt<Idx> for Range<Idx>
impl<Idx: Clone + Ord> PartialRangeExt<Idx> for Range<Idx>
Source§fn end_bound(&self) -> Option<RangeEnd<Idx>>
fn end_bound(&self) -> Option<RangeEnd<Idx>>
Returns the upper bound, or
None if the range is unbounded above.Source§fn clamp_exclusive(
&self,
start: impl Into<Idx>,
exclusive_end: impl Into<Idx>,
) -> Range<Idx>
fn clamp_exclusive( &self, start: impl Into<Idx>, exclusive_end: impl Into<Idx>, ) -> Range<Idx>
Restricts the range to the window
start..exclusive_end. Read moreSource§fn clamp_inclusive(
&self,
start: impl Into<Idx>,
inclusive_end: impl Into<Idx>,
) -> Range<Idx>
fn clamp_inclusive( &self, start: impl Into<Idx>, inclusive_end: impl Into<Idx>, ) -> Range<Idx>
Restricts the range to the window
start..=inclusive_end. Read moreSource§fn clamp_right_inclusive(&self, inclusive_end: impl Into<Idx>) -> Range<Idx>
fn clamp_right_inclusive(&self, inclusive_end: impl Into<Idx>) -> Range<Idx>
Caps the upper bound at
inclusive_end.Source§fn clamp_right_exclusive(&self, exclusive_end: impl Into<Idx>) -> Range<Idx>
fn clamp_right_exclusive(&self, exclusive_end: impl Into<Idx>) -> Range<Idx>
Caps the upper bound at
exclusive_end.Source§fn clamp_left(&self, start: impl Into<Idx>) -> PartialRange<Idx> ⓘ
fn clamp_left(&self, start: impl Into<Idx>) -> PartialRange<Idx> ⓘ
Raises the lower bound to at least
start, preserving boundedness
above. Read moreSource§fn intersection<R>(&self, other: &R) -> PartialRange<Idx> ⓘwhere
R: PartialRangeExt<Idx>,
fn intersection<R>(&self, other: &R) -> PartialRange<Idx> ⓘwhere
R: PartialRangeExt<Idx>,
Returns the overlap between this range and
other. Read moreSource§impl<Idx> RangeExt<Idx> for Range<Idx>
impl<Idx> RangeExt<Idx> for Range<Idx>
Source§fn end_inclusive(&self) -> Idx
fn end_inclusive(&self) -> Idx
Returns the inclusive upper bound. Read more
Source§fn end_exclusive(&self) -> Option<Idx>
fn end_exclusive(&self) -> Option<Idx>
Returns the exclusive upper bound, or
None if it would exceed the
maximum index value, that is, if the range ends inclusively at the
maximum.Source§fn clamp_to(&self, start: impl Into<Idx>, end: impl Into<Idx>) -> Range<Idx>
fn clamp_to(&self, start: impl Into<Idx>, end: impl Into<Idx>) -> Range<Idx>
Restricts the range to the bounds
start..end. Read moreSource§fn clamp_right(&self, end: impl Into<Idx>) -> Range<Idx>
fn clamp_right(&self, end: impl Into<Idx>) -> Range<Idx>
Lowers the upper bound to at most
end.Source§impl<Idx: Clone> RangeStart<Idx> for Range<Idx>
impl<Idx: Clone> RangeStart<Idx> for Range<Idx>
impl<Idx: PartialEq> StructuralPartialEq for Range<Idx>
Auto Trait Implementations§
impl<Idx> Freeze for Range<Idx>where
Idx: Freeze,
impl<Idx> RefUnwindSafe for Range<Idx>where
Idx: RefUnwindSafe,
impl<Idx> Send for Range<Idx>where
Idx: Send,
impl<Idx> Sync for Range<Idx>where
Idx: Sync,
impl<Idx> Unpin for Range<Idx>where
Idx: Unpin,
impl<Idx> UnsafeUnpin for Range<Idx>where
Idx: UnsafeUnpin,
impl<Idx> UnwindSafe for Range<Idx>where
Idx: 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