std-method

ExactSizeIterator::len — count without consuming

Read the exact number of remaining items from an exact-size iterator. Unlike count, len does not consume the iterator. Expected stdout (not executed): 3 2 Common mistake: Expecting len to be available on every Iterator.

Formal Syntax & Structure

rust syntaxrust
fn len(&self) -> usize

Working Example

Example Snippetrust
fn main() {    let mut slots = [2, 4, 6].into_iter();    println!("{}", slots.len());    slots.next_back();    println!("{}", slots.len());}
Rust Reference