Iterators
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 build a shuffling iterator over a slice: returns references to slice elements in random order
Last modified: Monday, 10 February 2020, 4:10 PM