Iterators

So far, we've assumed that the reader has been at least passingly familiar with Rust iterators. It's possible that you've used them extensively but have never written your own iterator implementation. That knowledge is important for what follows and we'll discuss Rust's iteration facility now.

A Rust iterator is any type that implements std::iter::Iterator. The Iterator trait has an interior Item type that allows the familiar iterator functions, such as next(&mut self) -> Option<Self::Item>, to be defined in terms of that generic Item. Many of the iterator functions are, well, functional in nature: map, filter, and fold are all higher-order functions on a stream of Item. Many of the iterator functions are searches on that stream ...

Get Hands-On Concurrency with Rust now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.