Struct Enumerate
#[must_use = "iterators are lazy and do nothing unless consumed"]
pub struct Enumerate<I> { pub(in ::iter::adapters::enumerate) iter: I, pub(in ::iter::adapters::enumerate) count: usize }
An iterator that yields the current count and the element during iteration.
This struct is created by the enumerate method on Iterator. See its
documentation for more.
Fields
iter: Icount: usize
Implementations
impl<I> Enumerate<I>
const fn new(iter: I) -> Enumerate<I>fn next_index(&self) -> usizeRetrieve the current position of the iterator.
If the iterator has not advanced, the position returned will be 0.
The position may also exceed the bounds of the iterator to allow for calculating the displacement of the iterator from following calls to
Iterator::next.Examples
let arr = ; let mut iter = arr.iter.enumerate; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!; assert_eq!;
Trait Implementations
impl<I> DoubleEndedIterator for Enumerate<I>
where
I: ExactSizeIterator + DoubleEndedIterator,
fn next_back(&mut self) -> Option<(usize, <I as Iterator>::Item)>fn nth_back(&mut self, n: usize) -> Option<(usize, <I as Iterator>::Item)>fn try_rfold<Acc, Fold, R>(&mut self, init: Acc, fold: Fold) -> R where Self: Sized, Fold: FnMut(Acc, Self::Item) -> R, R: Try<Output = Acc>,fn rfold<Acc, Fold>(self, init: Acc, fold: Fold) -> Acc where Fold: FnMut(Acc, Self::Item) -> Acc,fn advance_back_by(&mut self, n: usize) -> Result<(), NonZero<usize>>
impl<I> ExactSizeIterator for Enumerate<I>
where
I: ExactSizeIterator,
fn len(&self) -> usizefn is_empty(&self) -> bool
impl<I> FusedIterator for Enumerate<I>
where
I: FusedIterator,
impl<I> Iterator for Enumerate<I>
where
I: Iterator,
type Item = (usize, <I as Iterator>::Item);fn next(&mut self) -> Option<(usize, <I as Iterator>::Item)>Overflow Behavior
The method does no guarding against overflows, so enumerating more than
usize::MAXelements either produces the wrong result or panics. If overflow checks are enabled, a panic is guaranteed.Panics
Might panic if the index of the element overflows a
usize.fn size_hint(&self) -> (usize, Option<usize>)fn nth(&mut self, n: usize) -> Option<(usize, I::Item)>fn count(self) -> usizefn try_fold<Acc, Fold, R>(&mut self, init: Acc, fold: Fold) -> R where Self: Sized, Fold: FnMut(Acc, Self::Item) -> R, R: Try<Output = Acc>,fn fold<Acc, Fold>(self, init: Acc, fold: Fold) -> Acc where Fold: FnMut(Acc, Self::Item) -> Acc,fn advance_by(&mut self, n: usize) -> Result<(), NonZero<usize>>unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> <Self as Iterator>::Item where Self: TrustedRandomAccessNoCoerce,
impl<I> SourceIter for Enumerate<I>
where
I: SourceIter,
type Source = <I as SourceIter>::Source;unsafe fn as_inner(&mut self) -> &mut I::Source
impl<I> TrustedLen for Enumerate<I>
where
I: TrustedLen,
impl<I> TrustedRandomAccess for Enumerate<I>
where
I: TrustedRandomAccess,
impl<I> TrustedRandomAccessNoCoerce for Enumerate<I>
where
I: TrustedRandomAccessNoCoerce,
const MAY_HAVE_SIDE_EFFECT: bool = I::MAY_HAVE_SIDE_EFFECT;
impl<I: Clone> Clone for Enumerate<I>
fn clone(&self) -> Enumerate<I>
impl<I: Debug> Debug for Enumerate<I>
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl<I: Default> Default for Enumerate<I>
fn default() -> SelfCreates an
Enumerateiterator from the default value ofI# use slice; # use Enumerate; let iter: = Defaultdefault; assert_eq!;
impl<I: InPlaceIterable> InPlaceIterable for Enumerate<I>
const EXPAND_BY: Option<NonZero<usize>> = I::EXPAND_BY;const MERGE_BY: Option<NonZero<usize>> = I::MERGE_BY;
impl<I: TrustedFused> TrustedFused for Enumerate<I>
Auto Trait Implementations
impl<I> Freeze for Enumerate<I>
where
I: Freeze,
impl<I> RefUnwindSafe for Enumerate<I>
where
I: RefUnwindSafe,
impl<I> Send for Enumerate<I>
where
I: Send,
impl<I> Sync for Enumerate<I>
where
I: Sync,
impl<I> Unpin for Enumerate<I>
where
I: Unpin,
impl<I> UnsafeUnpin for Enumerate<I>
where
I: UnsafeUnpin,
impl<I> UnwindSafe for Enumerate<I>
where
I: UnwindSafe,
Blanket Implementations
impl<I> IntoIterator for Enumerate<I>
where
I: Iterator,
type Item = <I as Iterator>::Item;type IntoIter = I;fn into_iter(self) -> I
impl<T> Any for Enumerate<I>
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for Enumerate<I>
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for Enumerate<I>
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for Enumerate<I>
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for Enumerate<I>
fn from(t: T) -> TReturns the argument unchanged.
impl<T> SizeHint for Enumerate<I>
where
T: ?Sized,
fn lower_bound(&self) -> usizefn upper_bound(&self) -> Option<usize>
impl<T> SizedTypeProperties for Enumerate<I>
impl<T, U> Into<U> for Enumerate<I>
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 Enumerate<I>
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 Enumerate<I>
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>