pub struct Range<Idx> {
pub start: Idx,
pub end: Idx,
}new_range_api #125687)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.
ยงExamples
#![feature(new_range_api)]
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: Idxnew_range_api #125687)The lower bound of the range (inclusive).
end: Idxnew_range_api #125687)The 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>
Sourcepub const fn contains<U>(&self, item: &U) -> bool
๐ฌThis is a nightly-only experimental API. (new_range_api #125687)
pub const fn contains<U>(&self, item: &U) -> bool
new_range_api #125687)Returns true if item is contained in the range.
ยงExamples
#![feature(new_range_api)]
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));Sourcepub const fn is_empty(&self) -> boolwhere
Idx: PartialOrd,
๐ฌThis is a nightly-only experimental API. (new_range_api #125687)
pub const fn is_empty(&self) -> boolwhere
Idx: PartialOrd,
new_range_api #125687)Returns true if the range contains no items.
ยงExamples
#![feature(new_range_api)]
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ยง
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>
Sourceยงimpl<A: Step> IntoIterator for Range<A>
impl<A: Step> IntoIterator for Range<A>
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<T> RangeBounds<T> for Range<T>
impl<T> RangeBounds<T> for Range<T>
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)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)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)