std-method
Iterator::find — first matching item
Search from the current cursor and stop after the first match. The matching item is consumed; subsequent calls can continue from the following item. Expected stdout (not executed): Some(12) Some(8) Common mistake: Treating None as a panic or expecting every matching item.
Formal Syntax & Structure
rust syntaxrust
fn find<P>(&mut self, predicate: P) -> Option<Self::Item> where Self: Sized, P: FnMut(&Self::Item) -> boolWorking Example
Example Snippetrust
fn main() { let mut prices = [3, 12, 8, 20].into_iter(); println!("{:?}", prices.find(|p| *p > 10)); println!("{:?}", prices.next());}