Use .any() to check if one item matches a condition and .all() to verify every item matches in a Rust iterator.
Use .any() to check if at least one item in an iterator matches a condition and .all() to verify every item matches. Both methods take a closure and return a boolean.
let numbers = vec![1, 2, 3, 4, 5];
let has_even = numbers.iter().any(|&n| n % 2 == 0);
let all_positive = numbers.iter().all(|&n| n > 0);
These tools let you quickly check a list of items without writing a loop. Use 'any' to see if at least one item fits your rule, like finding a single even number. Use 'all' to confirm every single item follows the rule, like ensuring all numbers are positive.