How to use Iterator any and all

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);