std-method
Iterator::all — require every item to pass
Return false as soon as one item fails. An empty iterator returns true because no failing item exists. Expected stdout (not executed): false Some(5) Common mistake: Assuming all proves that at least one item exists.
Formal Syntax & Structure
rust syntaxrust
fn all<F>(&mut self, f: F) -> bool where Self: Sized, F: FnMut(Self::Item) -> boolWorking Example
Example Snippetrust
fn main() { let mut quantities = [3, 0, 5].into_iter(); println!("{}", quantities.all(|n| n > 0)); println!("{:?}", quantities.next());}