Struct Enumerate

struct Enumerate<I> { ... }

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.

Implementations

impl<I> Enumerate<I>

fn next_index(self: &Self) -> usize

Retrieve 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

#![feature(next_index)]

let arr = ['a', 'b'];

let mut iter = arr.iter().enumerate();

assert_eq!(iter.next_index(), 0);
assert_eq!(iter.next(), Some((0, &'a')));

assert_eq!(iter.next_index(), 1);
assert_eq!(iter.next_index(), 1);
assert_eq!(iter.next(), Some((1, &'b')));

assert_eq!(iter.next_index(), 2);
assert_eq!(iter.next(), None);
assert_eq!(iter.next_index(), 2);

impl<I> DoubleEndedIterator for Enumerate<I>

fn next_back(self: &mut Self) -> Option<(usize, <I as Iterator>::Item)>
fn nth_back(self: &mut Self, n: usize) -> Option<(usize, <I as Iterator>::Item)>
fn try_rfold<Acc, Fold, R>(self: &mut Self, init: Acc, fold: Fold) -> R
where
    Self: Sized,
    Fold: FnMut(Acc, <Self as >::Item) -> R,
    R: Try<Output = Acc>
fn rfold<Acc, Fold>(self: Self, init: Acc, fold: Fold) -> Acc
where
    Fold: FnMut(Acc, <Self as >::Item) -> Acc
fn advance_back_by(self: &mut Self, n: usize) -> Result<(), NonZero<usize>>

impl<I> ExactSizeIterator for Enumerate<I>

fn len(self: &Self) -> usize
fn is_empty(self: &Self) -> bool

impl<I> Freeze for Enumerate<I>

impl<I> FusedIterator for Enumerate<I>

impl<I> IntoIterator for Enumerate<I>

fn into_iter(self: Self) -> I

impl<I> Iterator for Enumerate<I>

fn next(self: &mut Self) -> Option<(usize, <I as Iterator>::Item)>

Overflow Behavior

The method does no guarding against overflows, so enumerating more than usize::MAX elements 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: &Self) -> (usize, Option<usize>)
fn nth(self: &mut Self, n: usize) -> Option<(usize, <I as >::Item)>
fn count(self: Self) -> usize
fn try_fold<Acc, Fold, R>(self: &mut Self, init: Acc, fold: Fold) -> R
where
    Self: Sized,
    Fold: FnMut(Acc, <Self as >::Item) -> R,
    R: Try<Output = Acc>
fn fold<Acc, Fold>(self: Self, init: Acc, fold: Fold) -> Acc
where
    Fold: FnMut(Acc, <Self as >::Item) -> Acc
fn advance_by(self: &mut Self, n: usize) -> Result<(), NonZero<usize>>

impl<I> RefUnwindSafe for Enumerate<I>

impl<I> Send for Enumerate<I>

impl<I> Sync for Enumerate<I>

impl<I> TrustedLen for Enumerate<I>

impl<I> Unpin for Enumerate<I>

impl<I> UnsafeUnpin for Enumerate<I>

impl<I> UnwindSafe for Enumerate<I>

impl<I: $crate::clone::Clone> Clone for Enumerate<I>

fn clone(self: &Self) -> Enumerate<I>

impl<I: $crate::fmt::Debug> Debug for Enumerate<I>

fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result

impl<I: Default> Default for Enumerate<I>

fn default() -> Self

Creates an Enumerate iterator from the default value of I

# use core::slice;
# use std::iter::Enumerate;
let iter: Enumerate<slice::Iter<'_, u8>> = Default::default();
assert_eq!(iter.len(), 0);

impl<T> Any for Enumerate<I>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for Enumerate<I>

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for Enumerate<I>

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> CloneToUninit for Enumerate<I>

unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)

impl<T> From for Enumerate<I>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T, U> Into for Enumerate<I>

fn into(self: Self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom for Enumerate<I>

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for Enumerate<I>

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>