Struct Range
pub struct Range<Idx> { pub start: Idx, pub end: Idx }
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>)][Bound] if you
need a type that can store an arbitrary range.
Examples
use Range;
assert_eq!;
assert_eq!;
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
impl<Idx: PartialOrd<Idx>> Range<Idx>
const fn contains<U>(&self, item: &U) -> bool where Idx: ~const PartialOrd<U>, U: ?Sized + ~const PartialOrd<Idx>,Returns
trueifitemis contained in the range.Examples
use Range; assert!; assert!; assert!; assert!; assert!; assert!; assert!; assert!; assert!; assert!;const fn is_empty(&self) -> bool where Idx: ~const PartialOrd,Returns
trueif the range contains no items.Examples
use Range; assert!; assert!; assert!;The range is empty if either side is incomparable:
use Range; assert!; assert!; assert!;
impl<Idx: Step> Range<Idx>
fn iter(&self) -> RangeIter<Idx>Creates an iterator over the elements within this range.
Shorthand for
.clone().into_iter()Examples
use Range; let mut i = from.iter.map; assert_eq!; assert_eq!; assert_eq!;
Trait Implementations
impl GetDisjointMutIndex for Range<usize>
fn is_in_bounds(&self, len: usize) -> boolfn is_overlapping(&self, other: &Self) -> bool
impl SliceIndex<ByteStr> for Range<usize>
type Output = ByteStr;fn get(self, slice: &ByteStr) -> Option<&Self::Output>fn get_mut(self, slice: &mut ByteStr) -> Option<&mut Self::Output>unsafe fn get_unchecked(self, slice: *const ByteStr) -> *const Self::Outputunsafe fn get_unchecked_mut(self, slice: *mut ByteStr) -> *mut Self::Outputfn index(self, slice: &ByteStr) -> &Self::Outputfn index_mut(self, slice: &mut ByteStr) -> &mut Self::Output
impl SliceIndex<str> for Range<usize>
type Output = str;fn get(self, slice: &str) -> Option<&Self::Output>fn get_mut(self, slice: &mut str) -> Option<&mut Self::Output>unsafe fn get_unchecked(self, slice: *const str) -> *const Self::Outputunsafe fn get_unchecked_mut(self, slice: *mut str) -> *mut Self::Outputfn index(self, slice: &str) -> &Self::Outputfn index_mut(self, slice: &mut str) -> &mut Self::Output
impl<A: Step> IntoIterator for Range<A>
type Item = A;type IntoIter = RangeIter<A>;fn into_iter(self) -> Self::IntoIter
impl<Idx: Copy> Copy for Range<Idx>
impl<Idx: Debug> Debug for Range<Idx>
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result
impl<Idx: Hash> Hash for Range<Idx>
fn hash<__H: Hasher>(&self, state: &mut __H)
impl<Idx: PartialEq> StructuralPartialEq for Range<Idx>
impl<Idx: ~const Clone> Clone for Range<Idx>
fn clone(&self) -> Self
impl<Idx: ~const Default> Default for Range<Idx>
fn default() -> Self
impl<Idx: ~const Eq> Eq for Range<Idx>
fn assert_fields_are_eq(&self)
impl<Idx: ~const PartialEq> PartialEq for Range<Idx>
fn eq(&self, other: &Self) -> bool
impl<T> From<Range<T>> for Range<T>
fn from(value: Range<T>) -> Self
impl<T> IntoBounds<T> for Range<T>
fn into_bounds(self) -> (Bound<T>, Bound<T>)
impl<T> RangeBounds<T> for Range<&T>
fn start_bound(&self) -> Bound<&T>fn end_bound(&self) -> Bound<&T>
impl<T> RangeBounds<T> for Range<T>
fn start_bound(&self) -> Bound<&T>fn end_bound(&self) -> Bound<&T>
impl<T> SliceIndex<[T]> for Range<usize>
type Output = [T];fn get(self, slice: &[T]) -> Option<&[T]>fn get_mut(self, slice: &mut [T]) -> Option<&mut [T]>unsafe fn get_unchecked(self, slice: *const [T]) -> *const [T]unsafe fn get_unchecked_mut(self, slice: *mut [T]) -> *mut [T]fn index(self, slice: &[T]) -> &[T]fn index_mut(self, slice: &mut [T]) -> &mut [T]
impl<T: CloneFromCell> CloneFromCell for Range<T>
Auto Trait Implementations
impl<Idx> Freeze for Range<Idx>
where
Idx: Freeze + Freeze,
impl<Idx> RefUnwindSafe for Range<Idx>
where
Idx: RefUnwindSafe + RefUnwindSafe,
impl<Idx> Send for Range<Idx>
where
Idx: Send + Send,
impl<Idx> Sync for Range<Idx>
where
Idx: Sync + Sync,
impl<Idx> Unpin for Range<Idx>
where
Idx: Unpin + Unpin,
impl<Idx> UnsafeUnpin for Range<Idx>
where
Idx: UnsafeUnpin + UnsafeUnpin,
impl<Idx> UnwindSafe for Range<Idx>
where
Idx: UnwindSafe + UnwindSafe,
Blanket Implementations
impl<T> Any for Range<Idx>
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for Range<Idx>
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for Range<Idx>
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for Range<Idx>
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for Range<Idx>
fn from(t: T) -> TReturns the argument unchanged.
impl<T> Printable for Range<Idx>
where
T: Copy + Debug,
impl<T> SizeHint for Range<Idx>
where
T: ?Sized,
fn lower_bound(&self) -> usizefn upper_bound(&self) -> Option<usize>
impl<T> SizedTypeProperties for Range<Idx>
impl<T, U> Into<U> for Range<Idx>
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for Range<Idx>
where
U: Into<T>,
type Error = never;fn try_from(value: U) -> Result<T, never>
impl<T, U> TryInto<U> for Range<Idx>
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>