Struct RangeInclusive
pub struct RangeInclusive<Idx> { pub(crate) start: Idx, pub(crate) end: Idx, pub(crate) exhausted: bool }
A range bounded inclusively below and above (start..=end).
The RangeInclusive start..=end contains all values with x >= start
and x <= end. It is empty unless start <= end.
This iterator is fused, but the specific values of start and end after
iteration has finished are unspecified other than that .is_empty()
will return true once no more values will be produced.
Examples
The start..=end syntax is a RangeInclusive:
assert_eq!;
assert_eq!;
let arr = ;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!; // This is a `RangeInclusive`
Fields
start: Idxend: Idxexhausted: bool
Implementations
impl RangeInclusive<usize>
const fn into_slice_range(self) -> Range<usize>Converts to an exclusive
RangeforSliceIndeximplementations. The caller is responsible for dealing withend == usize::MAX.
impl<Idx> RangeInclusive<Idx>
const fn new(start: Idx, end: Idx) -> SelfCreates a new inclusive range. Equivalent to writing
start..=end.Examples
use RangeInclusive; assert_eq!;const fn start(&self) -> &IdxReturns the lower bound of the range (inclusive).
When using an inclusive range for iteration, the values of
start()andend()are unspecified after the iteration ended. To determine whether the inclusive range is empty, use theis_empty()method instead of comparingstart() > end().Note: the value returned by this method is unspecified after the range has been iterated to exhaustion.
Examples
assert_eq!;const fn end(&self) -> &IdxReturns the upper bound of the range (inclusive).
When using an inclusive range for iteration, the values of
start()andend()are unspecified after the iteration ended. To determine whether the inclusive range is empty, use theis_empty()method instead of comparingstart() > end().Note: the value returned by this method is unspecified after the range has been iterated to exhaustion.
Examples
assert_eq!;const fn into_inner(self) -> (Idx, Idx)Destructures the
RangeInclusiveinto (lower bound, upper (inclusive) bound).Note: the value returned by this method is unspecified after the range has been iterated to exhaustion.
Examples
assert_eq!;
impl<Idx: PartialOrd<Idx>> RangeInclusive<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
assert!; assert!; assert!; assert!; assert!; assert!; assert!; assert!; assert!; assert!; assert!;This method always returns
falseafter iteration has finished:let mut r = 3..=5; assert!; for _ in r.by_ref // Precise field values are unspecified here assert!;const fn is_empty(&self) -> bool where Idx: ~const PartialOrd,Returns
trueif the range contains no items.Examples
assert!; assert!; assert!;The range is empty if either side is incomparable:
assert!; assert!; assert!;This method returns
trueafter iteration has finished:let mut r = 3..=5; for _ in r.by_ref // Precise field values are unspecified here assert!;
Trait Implementations
impl ExactSizeIterator for RangeInclusive<NonZero<u16>>
impl ExactSizeIterator for RangeInclusive<NonZero<u8>>
impl ExactSizeIterator for RangeInclusive<NonZero<usize>>
impl ExactSizeIterator for RangeInclusive<i16>
impl ExactSizeIterator for RangeInclusive<i8>
impl ExactSizeIterator for RangeInclusive<u16>
impl ExactSizeIterator for RangeInclusive<u8>
impl GetDisjointMutIndex for RangeInclusive<usize>
fn is_in_bounds(&self, len: usize) -> boolfn is_overlapping(&self, other: &Self) -> bool
impl SliceIndex<ByteStr> for RangeInclusive<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 RangeInclusive<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> DoubleEndedIterator for RangeInclusive<A>
fn next_back(&mut self) -> Option<A>fn nth_back(&mut self, n: usize) -> Option<A>fn try_rfold<B, F, R>(&mut self, init: B, f: F) -> R where Self: Sized, F: FnMut(B, Self::Item) -> R, R: Try<Output = B>,fn rfold<AAA, FFF>(self, init: AAA, fold: FFF) -> AAA where FFF: FnMut(AAA, Self::Item) -> AAA,
impl<A: Step> FusedIterator for RangeInclusive<A>
impl<A: Step> Iterator for RangeInclusive<A>
type Item = A;fn next(&mut self) -> Option<A>fn size_hint(&self) -> (usize, Option<usize>)fn count(self) -> usizefn nth(&mut self, n: usize) -> Option<A>fn try_fold<B, F, R>(&mut self, init: B, f: F) -> R where Self: Sized, F: FnMut(B, Self::Item) -> R, R: Try<Output = B>,fn fold<AAA, FFF>(self, init: AAA, fold: FFF) -> AAA where FFF: FnMut(AAA, Self::Item) -> AAA,fn last(self) -> Option<A>fn min(self) -> Option<A> where A: Ord,fn max(self) -> Option<A> where A: Ord,fn is_sorted(self) -> bool
impl<A: Step> RangeInclusiveIteratorImpl for RangeInclusive<A>
type Item = A;fn spec_try_fold<B, F, R>(&mut self, init: B, f: F) -> R where Self: Sized, F: FnMut(B, A) -> R, R: Try<Output = B>,fn spec_try_rfold<B, F, R>(&mut self, init: B, f: F) -> R where Self: Sized, F: FnMut(B, A) -> R, R: Try<Output = B>,
impl<A: TrustedStep> TrustedLen for RangeInclusive<A>
impl<Idx: Clone> Clone for RangeInclusive<Idx>
fn clone(&self) -> RangeInclusive<Idx>
impl<Idx: Debug> Debug for RangeInclusive<Idx>
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result
impl<Idx: Hash> Hash for RangeInclusive<Idx>
fn hash<__H: Hasher>(&self, state: &mut __H)
impl<Idx: PartialEq> StructuralPartialEq for RangeInclusive<Idx>
impl<Idx: ~const Eq> Eq for RangeInclusive<Idx>
fn assert_fields_are_eq(&self)
impl<Idx: ~const PartialEq> PartialEq for RangeInclusive<Idx>
fn eq(&self, other: &RangeInclusive<Idx>) -> bool
impl<T> From<RangeInclusive<T>> for RangeInclusive<T>
fn from(value: RangeInclusive<T>) -> Self
impl<T> IntoBounds<T> for RangeInclusive<T>
fn into_bounds(self) -> (Bound<T>, Bound<T>)
impl<T> RangeBounds<T> for RangeInclusive<&T>
fn start_bound(&self) -> Bound<&T>fn end_bound(&self) -> Bound<&T>
impl<T> RangeBounds<T> for RangeInclusive<T>
fn start_bound(&self) -> Bound<&T>fn end_bound(&self) -> Bound<&T>
impl<T> SliceIndex<[T]> for RangeInclusive<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: TrustedStep> RangeInclusiveIteratorImpl for RangeInclusive<T>
fn spec_try_fold<B, F, R>(&mut self, init: B, f: F) -> R where Self: Sized, F: FnMut(B, T) -> R, R: Try<Output = B>,fn spec_try_rfold<B, F, R>(&mut self, init: B, f: F) -> R where Self: Sized, F: FnMut(B, T) -> R, R: Try<Output = B>,
Auto Trait Implementations
impl<Idx> Freeze for RangeInclusive<Idx>
where
Idx: Freeze + Freeze,
impl<Idx> RefUnwindSafe for RangeInclusive<Idx>
where
Idx: RefUnwindSafe + RefUnwindSafe,
impl<Idx> Send for RangeInclusive<Idx>
where
Idx: Send + Send,
impl<Idx> Sync for RangeInclusive<Idx>
where
Idx: Sync + Sync,
impl<Idx> Unpin for RangeInclusive<Idx>
where
Idx: Unpin + Unpin,
impl<Idx> UnsafeUnpin for RangeInclusive<Idx>
where
Idx: UnsafeUnpin + UnsafeUnpin,
impl<Idx> UnwindSafe for RangeInclusive<Idx>
where
Idx: UnwindSafe + UnwindSafe,
Blanket Implementations
impl<I> IntoIterator for RangeInclusive<Idx>
where
I: Iterator,
type Item = <I as Iterator>::Item;type IntoIter = I;fn into_iter(self) -> I
impl<T> Any for RangeInclusive<Idx>
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for RangeInclusive<Idx>
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for RangeInclusive<Idx>
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for RangeInclusive<Idx>
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for RangeInclusive<Idx>
fn from(t: T) -> TReturns the argument unchanged.
impl<T> SizeHint for RangeInclusive<Idx>
where
T: ?Sized,
fn lower_bound(&self) -> usizefn upper_bound(&self) -> Option<usize>
impl<T> SizedTypeProperties for RangeInclusive<Idx>
impl<T, U> Into<U> for RangeInclusive<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 RangeInclusive<Idx>
where
U: Into<T>,
type Error = Infallible;fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto<U> for RangeInclusive<Idx>
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>