std-method

Iterator::next — advance one step

Use next to pull one value and advance the same stateful iterator. A mutable binding is needed for repeated calls on an owned iterator. Expected stdout (not executed): Some(40) Some(41) None Common mistake: Expecting next to restart the sequence each time.

Formal Syntax & Structure

rust syntaxrust
fn next(&mut self) -> Option<Self::Item>

Working Example

Example Snippetrust
fn main() {    let mut ticket = 40..42;    println!("{:?}", ticket.next());    println!("{:?}", ticket.next());    println!("{:?}", ticket.next());}
Rust Reference