std-method
Iterator::nth — skip to an offset
Consume preceding items and return the item at offset n from the current cursor. Repeated nth calls are relative to the remaining sequence. Expected stdout (not executed): Some(20) Some(30) Common mistake: Using nth as random access without consuming items.
Formal Syntax & Structure
rust syntaxrust
fn nth(&mut self, n: usize) -> Option<Self::Item>Working Example
Example Snippetrust
fn main() { let mut slots = [10, 20, 30, 40].into_iter(); println!("{:?} {:?}", slots.nth(1), slots.next());}