-
Book Overview & Buying
-
Table Of Contents
The Rust Programming Handbook
By :
At the core of functional-style data processing in Rust are iterators.
What is an iterator? It’s a tool that generates a sequence of values. What’s unique about Rust’s iterators is that they are lazy. This means they don’t produce all values at once; instead, they generate them one by one, only when you ask for them. This laziness makes them extremely efficient.
For example, imagine you must find the first line containing an error in a huge, multi-gigabyte log file that might not fit into memory. An iterator lets you process it line by line, stopping as soon as you find what you’re looking for, without ever loading the entire file. This demonstrates the power of doing work only when it’s needed.
Most collection types in Rust provide ways to create iterators. The most basic way to interact with an iterator is by calling its next() method repeatedly...