pub struct Range<Idx> {
pub start: Idx,
pub end: Idx,
}Expand description
A (half-open) range bounded inclusively below and exclusively above.
The Range contains all values with start <= x < end.
It is empty if start >= end.
Note that this type is not suited to represent all possible ranges. For example, Range<u8>
cannot represent the range that covers all of u8. Use (Bound<T>, Bound<T>) if you
need a type that can store an arbitrary range.
§Examples
use core::range::Range;
assert_eq!(Range::from(3..5), Range { start: 3, end: 5 });
assert_eq!(3 + 4 + 5, Range::from(3..6).into_iter().sum());§Edition notes
It is planned that the syntax start..end will construct this
type in a future edition, but it does not do so today.
Fields§
§start: IdxThe lower bound of the range (inclusive).
end: IdxThe upper bound of the range (exclusive).
Implementations§
Source§impl<Idx: Step> Range<Idx>
impl<Idx: Step> Range<Idx>
Source§impl<Idx: PartialOrd<Idx>> Range<Idx>
impl<Idx: PartialOrd<Idx>> Range<Idx>
1.96.0 (const: unstable) · 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
use core::range::Range;
assert!(!Range::from(3..5).contains(&2));
assert!( Range::from(3..5).contains(&3));
assert!( Range::from(3..5).contains(&4));
assert!(!Range::from(3..5).contains(&5));
assert!(!Range::from(3..3).contains(&3));
assert!(!Range::from(3..2).contains(&3));
assert!( Range::from(0.0..1.0).contains(&0.5));
assert!(!Range::from(0.0..1.0).contains(&f32::NAN));
assert!(!Range::from(0.0..f32::NAN).contains(&0.5));
assert!(!Range::from(f32::NAN..1.0).contains(&0.5));1.96.0 (const: unstable) · Sourcepub fn is_empty(&self) -> boolwhere
Idx: PartialOrd,
pub fn is_empty(&self) -> boolwhere
Idx: PartialOrd,
Returns true if the range contains no items.
§Examples
use core::range::Range;
assert!(!Range::from(3..5).is_empty());
assert!( Range::from(3..3).is_empty());
assert!( Range::from(3..2).is_empty());The range is empty if either side is incomparable:
Trait Implementations§
impl<T: CloneFromCell> CloneFromCell for Range<T>
impl<Idx: Copy> Copy for Range<Idx>
impl<Idx: Eq> Eq for Range<Idx>
Source§impl GetDisjointMutIndex for Range<usize>
impl GetDisjointMutIndex for Range<usize>
Source§fn is_in_bounds(&self, len: usize) -> bool
fn is_in_bounds(&self, len: usize) -> bool
get_disjoint_mut_helpers)true if self is in bounds for len slice elements.Source§fn is_overlapping(&self, other: &Self) -> bool
fn is_overlapping(&self, other: &Self) -> bool
get_disjoint_mut_helpers)Source§impl<T> IntoBounds<T> for Range<T>
impl<T> IntoBounds<T> for Range<T>
1.96.0 · Source§impl<A: Step> IntoIterator for Range<A>
impl<A: Step> IntoIterator for Range<A>
1.96.0 (const: unstable) · Source§impl<T> RangeBounds<T> for Range<T>
impl<T> RangeBounds<T> for Range<T>
1.96.0 (const: unstable) · Source§impl<T> RangeBounds<T> for Range<&T>
If you need to use this implementation where T is unsized,
consider using the RangeBounds impl for a 2-tuple of Bound<&T>,
i.e. replace start..end with (Bound::Included(start), Bound::Excluded(end)).
impl<T> RangeBounds<T> for Range<&T>
If you need to use this implementation where T is unsized,
consider using the RangeBounds impl for a 2-tuple of Bound<&T>,
i.e. replace start..end with (Bound::Included(start), Bound::Excluded(end)).
Source§impl SliceIndex<ByteStr> for Range<usize>
impl SliceIndex<ByteStr> for Range<usize>
Source§fn get(self, slice: &ByteStr) -> Option<&Self::Output>
fn get(self, slice: &ByteStr) -> Option<&Self::Output>
slice_index_methods)Source§fn get_mut(self, slice: &mut ByteStr) -> Option<&mut Self::Output>
fn get_mut(self, slice: &mut ByteStr) -> Option<&mut Self::Output>
slice_index_methods)Source§unsafe fn get_unchecked(self, slice: *const ByteStr) -> *const Self::Output
unsafe fn get_unchecked(self, slice: *const ByteStr) -> *const Self::Output
slice_index_methods)Source§unsafe fn get_unchecked_mut(self, slice: *mut ByteStr) -> *mut Self::Output
unsafe fn get_unchecked_mut(self, slice: *mut ByteStr) -> *mut Self::Output
slice_index_methods)1.96.0 (const: unstable) · Source§impl<T> SliceIndex<[T]> for Range<usize>
impl<T> SliceIndex<[T]> for Range<usize>
Source§fn get(self, slice: &[T]) -> Option<&[T]>
fn get(self, slice: &[T]) -> Option<&[T]>
slice_index_methods)Source§fn get_mut(self, slice: &mut [T]) -> Option<&mut [T]>
fn get_mut(self, slice: &mut [T]) -> Option<&mut [T]>
slice_index_methods)Source§unsafe fn get_unchecked(self, slice: *const [T]) -> *const [T]
unsafe fn get_unchecked(self, slice: *const [T]) -> *const [T]
slice_index_methods)Source§unsafe fn get_unchecked_mut(self, slice: *mut [T]) -> *mut [T]
unsafe fn get_unchecked_mut(self, slice: *mut [T]) -> *mut [T]
slice_index_methods)1.96.0 (const: unstable) · Source§impl SliceIndex<str> for Range<usize>
impl SliceIndex<str> for Range<usize>
Source§fn get(self, slice: &str) -> Option<&Self::Output>
fn get(self, slice: &str) -> Option<&Self::Output>
slice_index_methods)Source§fn get_mut(self, slice: &mut str) -> Option<&mut Self::Output>
fn get_mut(self, slice: &mut str) -> Option<&mut Self::Output>
slice_index_methods)Source§unsafe fn get_unchecked(self, slice: *const str) -> *const Self::Output
unsafe fn get_unchecked(self, slice: *const str) -> *const Self::Output
slice_index_methods)Source§unsafe fn get_unchecked_mut(self, slice: *mut str) -> *mut Self::Output
unsafe fn get_unchecked_mut(self, slice: *mut str) -> *mut Self::Output
slice_index_methods)