std-method
Iterator::last — consume to the final item
Return the final yielded item or None for empty input. The iterator is consumed; a generic forward-only iterator may need to traverse the whole finite sequence. Expected stdout (not executed): Some("done") Common mistake: Calling last on an unbounded infinite iterator.
Formal Syntax & Structure
rust syntaxrust
fn last(self) -> Option<Self::Item> where Self: SizedWorking Example
Example Snippetrust
fn main() { let end = ["queued", "running", "done"].into_iter().last(); println!("{end:?}");}