Iterators
Completion requirements
Iterators
Iterator
is a trait, with anItem
associated typeProduces a sequence of
Option<Item>
values on calls to itsnext()
methodUbiquitous in Rust code
Iterator Adapters
Implementation of
Iterator()
that operates by consuming the output of some passed iterator; essentially iterators over iteratorsUbiquitous in Rust code
Book pp. 329-351 are a bestiary of Standard Library stuff, worth studying in detail
FromIterator
Trait used by
collect()
to make an iterator into a collectionCan implement for your collection type to make it collectible
IntoIterator
Trait for getting a "canonical" iterator for a type
Makes the type work with
for
loopstrait IntoIterator where Self::IntoIter::Item == Self::Item { type Item; type IntoIter: Iterator; fn into_iter(self) -> Self::IntoIter; }
Every
Iterator
has a default implementation ofIntoIterator
, so that you canfor
loop over an explicit iterator
Implementing an Iterator
- Let's look at a "Neighborhood" iterator, which examines the squares around a target square in a grid. (playground)
Last modified: Monday, 22 July 2019, 3:27 AM