pub struct Range<Idx> { pub start: Idx, pub end: Idx,}Expand description
A (half-open) range bounded inclusively below and exclusively above(start..end).
The rangestart..end contains all values withstart <= x < end.It is empty ifstart >= end.
§Examples
Thestart..end syntax is aRange:
Fields§
§start: IdxThe lower bound of the range (inclusive).
end: IdxThe upper bound of the range (exclusive).
Implementations§
Source§impl<Idx>Range<Idx>where Idx:PartialOrd,
impl<Idx>Range<Idx>where Idx:PartialOrd,
1.35.0 (const: unstable) ·Sourcepub fncontains<U>(&self, item:&U) ->bool
pub fncontains<U>(&self, item:&U) ->bool
Returnstrue ifitem is contained in the range.
§Examples
assert!(!(3..5).contains(&2));assert!( (3..5).contains(&3));assert!( (3..5).contains(&4));assert!(!(3..5).contains(&5));assert!(!(3..3).contains(&3));assert!(!(3..2).contains(&3));assert!( (0.0..1.0).contains(&0.5));assert!(!(0.0..1.0).contains(&f32::NAN));assert!(!(0.0..f32::NAN).contains(&0.5));assert!(!(f32::NAN..1.0).contains(&0.5));1.47.0 (const: unstable) ·Sourcepub fnis_empty(&self) ->boolwhere Idx:PartialOrd,
pub fnis_empty(&self) ->boolwhere Idx:PartialOrd,
Returnstrue if the range contains no items.
§Examples
The range is empty if either side is incomparable:
Trait Implementations§
1.0.0 ·Source§impl<A>DoubleEndedIterator forRange<A>where A:Step,
impl<A>DoubleEndedIterator forRange<A>where A:Step,
Source§fnnext_back(&mut self) ->Option<A>
fnnext_back(&mut self) ->Option<A>
Source§fnnth_back(&mut self, n:usize) ->Option<A>
fnnth_back(&mut self, n:usize) ->Option<A>
nth element from the end of the iterator.Read moreSource§fnadvance_back_by(&mut self, n:usize) ->Result<(),NonZero<usize>>
fnadvance_back_by(&mut self, n:usize) ->Result<(),NonZero<usize>>
iter_advance_by #77404)n elements.Read more1.27.0 ·Source§fntry_rfold<B, F, R>(&mut self, init: B, f: F) -> R
fntry_rfold<B, F, R>(&mut self, init: B, f: F) -> R
Iterator::try_fold(): it takeselements starting from the back of the iterator.Read more1.0.0 ·Source§implExactSizeIterator forRange<i16>
implExactSizeIterator forRange<i16>
1.0.0 ·Source§implExactSizeIterator forRange<i32>
implExactSizeIterator forRange<i32>
1.0.0 ·Source§implExactSizeIterator forRange<i8>
implExactSizeIterator forRange<i8>
1.0.0 ·Source§implExactSizeIterator forRange<isize>
implExactSizeIterator forRange<isize>
1.0.0 ·Source§implExactSizeIterator forRange<u16>
implExactSizeIterator forRange<u16>
1.0.0 ·Source§implExactSizeIterator forRange<u32>
implExactSizeIterator forRange<u32>
1.0.0 ·Source§implExactSizeIterator forRange<u8>
implExactSizeIterator forRange<u8>
1.0.0 ·Source§implExactSizeIterator forRange<usize>
implExactSizeIterator forRange<usize>
Source§implGetDisjointMutIndex forRange<usize>
implGetDisjointMutIndex forRange<usize>
Source§fnis_in_bounds(&self, len:usize) ->bool
fnis_in_bounds(&self, len:usize) ->bool
get_disjoint_mut_helpers)true ifself is in bounds forlen slice elements.Source§impl<T>IntoBounds<T> forRange<T>
impl<T>IntoBounds<T> forRange<T>
1.0.0 ·Source§impl<A>Iterator forRange<A>where A:Step,
impl<A>Iterator forRange<A>where A:Step,
Source§fnsize_hint(&self) -> (usize,Option<usize>)
fnsize_hint(&self) -> (usize,Option<usize>)
Source§fncount(self) ->usize
fncount(self) ->usize
Source§fnadvance_by(&mut self, n:usize) ->Result<(),NonZero<usize>>
fnadvance_by(&mut self, n:usize) ->Result<(),NonZero<usize>>
iter_advance_by #77404)n elements.Read moreSource§fnnext_chunk<const N:usize>( &mut self,) ->Result<[Self::Item;N],IntoIter<Self::Item, N>>where Self:Sized,
fnnext_chunk<const N:usize>( &mut self,) ->Result<[Self::Item;N],IntoIter<Self::Item, N>>where Self:Sized,
iter_next_chunk #98326)N values.Read more1.28.0 ·Source§fnstep_by(self, step:usize) ->StepBy<Self>ⓘwhere Self:Sized,
fnstep_by(self, step:usize) ->StepBy<Self>ⓘwhere Self:Sized,
1.0.0 ·Source§fnchain<U>(self, other: U) ->Chain<Self, <U asIntoIterator>::IntoIter>ⓘ
fnchain<U>(self, other: U) ->Chain<Self, <U asIntoIterator>::IntoIter>ⓘ
1.0.0 ·Source§fnzip<U>(self, other: U) ->Zip<Self, <U asIntoIterator>::IntoIter>ⓘwhere Self:Sized, U:IntoIterator,
fnzip<U>(self, other: U) ->Zip<Self, <U asIntoIterator>::IntoIter>ⓘwhere Self:Sized, U:IntoIterator,
Source§fnintersperse(self, separator: Self::Item) ->Intersperse<Self>ⓘ
fnintersperse(self, separator: Self::Item) ->Intersperse<Self>ⓘ
iter_intersperse #79524)separator between adjacentitems of the original iterator.Read moreSource§fnintersperse_with<G>(self, separator: G) ->IntersperseWith<Self, G>ⓘ
fnintersperse_with<G>(self, separator: G) ->IntersperseWith<Self, G>ⓘ
iter_intersperse #79524)separatorbetween adjacent items of the original iterator.Read more1.0.0 ·Source§fnmap<B, F>(self, f: F) ->Map<Self, F>ⓘ
fnmap<B, F>(self, f: F) ->Map<Self, F>ⓘ
1.0.0 ·Source§fnfilter<P>(self, predicate: P) ->Filter<Self, P>ⓘ
fnfilter<P>(self, predicate: P) ->Filter<Self, P>ⓘ
1.0.0 ·Source§fnfilter_map<B, F>(self, f: F) ->FilterMap<Self, F>ⓘ
fnfilter_map<B, F>(self, f: F) ->FilterMap<Self, F>ⓘ
1.0.0 ·Source§fnenumerate(self) ->Enumerate<Self>ⓘwhere Self:Sized,
fnenumerate(self) ->Enumerate<Self>ⓘwhere Self:Sized,
1.0.0 ·Source§fnskip_while<P>(self, predicate: P) ->SkipWhile<Self, P>ⓘ
fnskip_while<P>(self, predicate: P) ->SkipWhile<Self, P>ⓘ
1.0.0 ·Source§fntake_while<P>(self, predicate: P) ->TakeWhile<Self, P>ⓘ
fntake_while<P>(self, predicate: P) ->TakeWhile<Self, P>ⓘ
1.57.0 ·Source§fnmap_while<B, P>(self, predicate: P) ->MapWhile<Self, P>ⓘ
fnmap_while<B, P>(self, predicate: P) ->MapWhile<Self, P>ⓘ
1.0.0 ·Source§fnskip(self, n:usize) ->Skip<Self>ⓘwhere Self:Sized,
fnskip(self, n:usize) ->Skip<Self>ⓘwhere Self:Sized,
n elements.Read more1.0.0 ·Source§fntake(self, n:usize) ->Take<Self>ⓘwhere Self:Sized,
fntake(self, n:usize) ->Take<Self>ⓘwhere Self:Sized,
n elements, or fewerif the underlying iterator ends sooner.Read more1.0.0 ·Source§fnflat_map<U, F>(self, f: F) ->FlatMap<Self, U, F>ⓘ
fnflat_map<U, F>(self, f: F) ->FlatMap<Self, U, F>ⓘ
1.29.0 ·Source§fnflatten(self) ->Flatten<Self>ⓘ
fnflatten(self) ->Flatten<Self>ⓘ
Source§fnmap_windows<F, R, const N:usize>(self, f: F) ->MapWindows<Self, F, N>ⓘ
fnmap_windows<F, R, const N:usize>(self, f: F) ->MapWindows<Self, F, N>ⓘ
iter_map_windows #87155)f for each contiguous window of sizeN overself and returns an iterator over the outputs off. Likeslice::windows(),the windows during mapping overlap as well.Read more1.0.0 ·Source§fninspect<F>(self, f: F) ->Inspect<Self, F>ⓘ
fninspect<F>(self, f: F) ->Inspect<Self, F>ⓘ
1.0.0 ·Source§fnby_ref(&mut self) -> &mut Selfwhere Self:Sized,
fnby_ref(&mut self) -> &mut Selfwhere Self:Sized,
Iterator.Read moreSource§fntry_collect<B>( &mut self,) -> <<Self::Item asTry>::Residual asResidual<B>>::TryType
fntry_collect<B>( &mut self,) -> <<Self::Item asTry>::Residual asResidual<B>>::TryType
iterator_try_collect #94047)Source§fncollect_into<E>(self, collection:&mut E) ->&mut E
fncollect_into<E>(self, collection:&mut E) ->&mut E
iter_collect_into #94780)1.0.0 ·Source§fnpartition<B, F>(self, f: F) ->(B, B)
fnpartition<B, F>(self, f: F) ->(B, B)
Source§fnpartition_in_place<'a, T, P>(self, predicate: P) ->usize
fnpartition_in_place<'a, T, P>(self, predicate: P) ->usize
iter_partition_in_place #62543)true precede all those that returnfalse.Returns the number oftrue elements found.Read moreSource§fnis_partitioned<P>(self, predicate: P) ->bool
fnis_partitioned<P>(self, predicate: P) ->bool
iter_is_partitioned #62544)true precede all those that returnfalse.Read more1.27.0 ·Source§fntry_fold<B, F, R>(&mut self, init: B, f: F) -> R
fntry_fold<B, F, R>(&mut self, init: B, f: F) -> R
1.27.0 ·Source§fntry_for_each<F, R>(&mut self, f: F) -> R
fntry_for_each<F, R>(&mut self, f: F) -> R
1.0.0 ·Source§fnfold<B, F>(self, init: B, f: F) -> B
fnfold<B, F>(self, init: B, f: F) -> B
1.51.0 ·Source§fnreduce<F>(self, f: F) ->Option<Self::Item>
fnreduce<F>(self, f: F) ->Option<Self::Item>
Source§fntry_reduce<R>( &mut self, f: implFnMut(Self::Item, Self::Item) -> R,) -> <<R asTry>::Residual asResidual<Option<<R asTry>::Output>>>::TryType
fntry_reduce<R>( &mut self, f: implFnMut(Self::Item, Self::Item) -> R,) -> <<R asTry>::Residual asResidual<Option<<R asTry>::Output>>>::TryType
iterator_try_reduce #87053)1.0.0 ·Source§fnall<F>(&mut self, f: F) ->bool
fnall<F>(&mut self, f: F) ->bool
1.0.0 ·Source§fnany<F>(&mut self, f: F) ->bool
fnany<F>(&mut self, f: F) ->bool
1.0.0 ·Source§fnfind<P>(&mut self, predicate: P) ->Option<Self::Item>
fnfind<P>(&mut self, predicate: P) ->Option<Self::Item>
1.30.0 ·Source§fnfind_map<B, F>(&mut self, f: F) ->Option<B>
fnfind_map<B, F>(&mut self, f: F) ->Option<B>
Source§fntry_find<R>( &mut self, f: implFnMut(&Self::Item) -> R,) -> <<R asTry>::Residual asResidual<Option<Self::Item>>>::TryType
fntry_find<R>( &mut self, f: implFnMut(&Self::Item) -> R,) -> <<R asTry>::Residual asResidual<Option<Self::Item>>>::TryType
try_find #63178)1.0.0 ·Source§fnposition<P>(&mut self, predicate: P) ->Option<usize>
fnposition<P>(&mut self, predicate: P) ->Option<usize>
1.0.0 ·Source§fnrposition<P>(&mut self, predicate: P) ->Option<usize>
fnrposition<P>(&mut self, predicate: P) ->Option<usize>
1.6.0 ·Source§fnmax_by_key<B, F>(self, f: F) ->Option<Self::Item>
fnmax_by_key<B, F>(self, f: F) ->Option<Self::Item>
1.15.0 ·Source§fnmax_by<F>(self, compare: F) ->Option<Self::Item>
fnmax_by<F>(self, compare: F) ->Option<Self::Item>
1.6.0 ·Source§fnmin_by_key<B, F>(self, f: F) ->Option<Self::Item>
fnmin_by_key<B, F>(self, f: F) ->Option<Self::Item>
1.15.0 ·Source§fnmin_by<F>(self, compare: F) ->Option<Self::Item>
fnmin_by<F>(self, compare: F) ->Option<Self::Item>
1.0.0 ·Source§fnrev(self) ->Rev<Self>ⓘwhere Self:Sized +DoubleEndedIterator,
fnrev(self) ->Rev<Self>ⓘwhere Self:Sized +DoubleEndedIterator,
1.0.0 ·Source§fnunzip<A, B, FromA, FromB>(self) ->(FromA, FromB)
fnunzip<A, B, FromA, FromB>(self) ->(FromA, FromB)
1.36.0 ·Source§fncopied<'a, T>(self) ->Copied<Self>ⓘ
fncopied<'a, T>(self) ->Copied<Self>ⓘ
Source§fnarray_chunks<const N:usize>(self) ->ArrayChunks<Self, N>ⓘwhere Self:Sized,
fnarray_chunks<const N:usize>(self) ->ArrayChunks<Self, N>ⓘwhere Self:Sized,
iter_array_chunks #100450)N elements of the iterator at a time.Read more1.11.0 ·Source§fnproduct<P>(self) -> P
fnproduct<P>(self) -> P
Source§fncmp_by<I, F>(self, other: I, cmp: F) ->Ordering
fncmp_by<I, F>(self, other: I, cmp: F) ->Ordering
iter_order_by #64295)Iterator with thoseof another with respect to the specified comparison function.Read more1.5.0 ·Source§fnpartial_cmp<I>(self, other: I) ->Option<Ordering>
fnpartial_cmp<I>(self, other: I) ->Option<Ordering>
PartialOrd elements ofthisIterator with those of another. The comparison works like short-circuitevaluation, returning a result without comparing the remaining elements.As soon as an order can be determined, the evaluation stops and a result is returned.Read moreSource§fnpartial_cmp_by<I, F>(self, other: I, partial_cmp: F) ->Option<Ordering>
fnpartial_cmp_by<I, F>(self, other: I, partial_cmp: F) ->Option<Ordering>
iter_order_by #64295)Iterator with thoseof another with respect to the specified comparison function.Read moreSource§fneq_by<I, F>(self, other: I, eq: F) ->bool
fneq_by<I, F>(self, other: I, eq: F) ->bool
iter_order_by #64295)1.5.0 ·Source§fnle<I>(self, other: I) ->bool
fnle<I>(self, other: I) ->bool
Iterator arelexicographicallyless or equal to those of another.Read more1.5.0 ·Source§fngt<I>(self, other: I) ->bool
fngt<I>(self, other: I) ->bool
Iterator arelexicographicallygreater than those of another.Read more1.5.0 ·Source§fnge<I>(self, other: I) ->bool
fnge<I>(self, other: I) ->bool
Iterator arelexicographicallygreater than or equal to those of another.Read more1.82.0 ·Source§fnis_sorted_by<F>(self, compare: F) ->bool
fnis_sorted_by<F>(self, compare: F) ->bool
1.82.0 ·Source§fnis_sorted_by_key<F, K>(self, f: F) ->bool
fnis_sorted_by_key<F, K>(self, f: F) ->bool
1.28.0 (const: unstable) ·Source§impl<T>RangeBounds<T> forRange<&T>
If you need to use this implementation whereT is unsized,consider using theRangeBounds impl for a 2-tuple ofBound<&T>,i.e. replacestart..end with(Bound::Included(start), Bound::Excluded(end)).
impl<T>RangeBounds<T> forRange<&T>
If you need to use this implementation whereT is unsized,consider using theRangeBounds impl for a 2-tuple ofBound<&T>,i.e. replacestart..end with(Bound::Included(start), Bound::Excluded(end)).
1.28.0 (const: unstable) ·Source§impl<T>RangeBounds<T> forRange<T>
impl<T>RangeBounds<T> forRange<T>
1.15.0 (const:unstable) ·Source§impl<T>SliceIndex<[T]> forRange<usize>
The methodsindex andindex_mut panic if:
impl<T>SliceIndex<[T]> forRange<usize>
The methodsindex andindex_mut panic if:
- the start of the range is greater than the end of the range or
- the end of the range is out of bounds.
Source§fnget(self, slice: &[T]) ->Option<&[T]>
fnget(self, slice: &[T]) ->Option<&[T]>
slice_index_methods)Source§fnget_mut(self, slice: &mut[T]) ->Option<&mut[T]>
fnget_mut(self, slice: &mut[T]) ->Option<&mut[T]>
slice_index_methods)Source§unsafe fnget_unchecked(self, slice:*const[T]) ->*const[T]
unsafe fnget_unchecked(self, slice:*const[T]) ->*const[T]
slice_index_methods)Source§unsafe fnget_unchecked_mut(self, slice:*mut[T]) ->*mut[T]
unsafe fnget_unchecked_mut(self, slice:*mut[T]) ->*mut[T]
slice_index_methods)Source§implSliceIndex<ByteStr> forRange<usize>
implSliceIndex<ByteStr> forRange<usize>
Source§fnget( self, slice: &ByteStr,) ->Option<&<Range<usize> asSliceIndex<ByteStr>>::Output>
fnget( self, slice: &ByteStr,) ->Option<&<Range<usize> asSliceIndex<ByteStr>>::Output>
slice_index_methods)Source§fnget_mut( self, slice: &mutByteStr,) ->Option<&mut <Range<usize> asSliceIndex<ByteStr>>::Output>
fnget_mut( self, slice: &mutByteStr,) ->Option<&mut <Range<usize> asSliceIndex<ByteStr>>::Output>
slice_index_methods)Source§unsafe fnget_unchecked( self, slice:*constByteStr,) ->*const<Range<usize> asSliceIndex<ByteStr>>::Output
unsafe fnget_unchecked( self, slice:*constByteStr,) ->*const<Range<usize> asSliceIndex<ByteStr>>::Output
slice_index_methods)Source§unsafe fnget_unchecked_mut( self, slice:*mutByteStr,) ->*mut<Range<usize> asSliceIndex<ByteStr>>::Output
unsafe fnget_unchecked_mut( self, slice:*mutByteStr,) ->*mut<Range<usize> asSliceIndex<ByteStr>>::Output
slice_index_methods)1.20.0 (const:unstable) ·Source§implSliceIndex<str> forRange<usize>
Implements substring slicing with syntax&self[begin .. end] or&mut self[begin .. end].
implSliceIndex<str> forRange<usize>
Implements substring slicing with syntax&self[begin .. end] or&mut self[begin .. end].
Returns a slice of the given string from the byte range[begin,end).
This operation isO(1).
Prior to 1.20.0, these indexing operations were still supported bydirect implementation ofIndex andIndexMut.
§Panics
Panics ifbegin orend does not point to the starting byte offset ofa character (as defined byis_char_boundary), ifbegin > end, or ifend > len.
§Examples
Source§fnget(self, slice: &str) ->Option<&<Range<usize> asSliceIndex<str>>::Output>
fnget(self, slice: &str) ->Option<&<Range<usize> asSliceIndex<str>>::Output>
slice_index_methods)Source§fnget_mut( self, slice: &mutstr,) ->Option<&mut <Range<usize> asSliceIndex<str>>::Output>
fnget_mut( self, slice: &mutstr,) ->Option<&mut <Range<usize> asSliceIndex<str>>::Output>
slice_index_methods)Source§unsafe fnget_unchecked( self, slice:*conststr,) ->*const<Range<usize> asSliceIndex<str>>::Output
unsafe fnget_unchecked( self, slice:*conststr,) ->*const<Range<usize> asSliceIndex<str>>::Output
slice_index_methods)Source§unsafe fnget_unchecked_mut( self, slice:*mutstr,) ->*mut<Range<usize> asSliceIndex<str>>::Output
unsafe fnget_unchecked_mut( self, slice:*mutstr,) ->*mut<Range<usize> asSliceIndex<str>>::Output
slice_index_methods)