liveBook · Manning

All

As explained in Learn Rust in a Month of Lunches

An all operation returns a Boolean indicating whether every item in a collection satisfies a condition, or is truthy when no condition is specified.

all is an iterator method that returns true only when every item satisfies a condition. Pass it a closure that receives each item and returns true or false. section 9.1.3

When an iterator yields references, match the closure pattern to those references. For example, iter().all(|&x| x.is_alphabetic()) checks the characters themselves rather than their references. section 9.1.3

Checking every character

let smaller_vec = ('A'..'z').collect::<Vec<char>>(); println!("All alphabetic? {}", smaller_vec.iter().all(|&x| x.is_alphabetic())); println!("All less than 행? {}", smaller_vec.iter().all(|&x| x < '행')); This prints false for the alphabetic check because the range includes nonalphabetic characters, and true for the comparison with 행. section 9.1.3

The method accepts a closure through a generic type. Its signature uses &mut self and requires F: FnMut(Self::Item) -> bool, meaning the closure receives an iterator item and returns a Boolean. section 12.1

Use all alongside other iterator checks:

  • Use any when one matching item is enough; it can stop as soon as it finds a match. section 9.1.3
  • Use find when you need the matching item, or position when you need its index. section 9.3

How Learn Rust in a Month of Lunches covers it

How deep it goes
Explains predicate use, reference handling, and the FnMut signature without descending into iterator internals.
Examples
Uses character ranges to test alphabetic characters and ordering against a Korean character.
What it assumes
Assumes basic iterator familiarity while defining closure arguments, generic types, and FnMut in the method signature.
What you can do after
Apply it via Rust iterator methods to test collection-wide conditions with closures.
How it connects
Connects iterators, closures, FnMut, any, find, and position.

Also explained in

Compare how 4 books explain all →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Rust in a Month of Lunches. The section links point to the parts of the book it draws on.