Iterator
(المكرر)
The Iterator
trait supports iterating over values in a collection. It requires a next
method and provides lots of methods. Many standard library types implement Iterator
, and you can implement it yourself, too:
Speaker Notes
This slide should take about 5 minutes.
-
The
Iterator
trait implements many common functional programming operations over collections (e.g.map
,filter
,reduce
, etc). This is the trait where you can find all the documentation about them. In Rust these functions should produce the code as efficient as equivalent imperative implementations. -
IntoIterator
is the trait that makes for loops work. It is implemented by collection types such asVec<T>
and references to them such as&Vec<T>
and&[T]
. Ranges also implement it. This is why you can iterate over a vector withfor i in some_vec { .. }
butsome_vec.next()
doesn’t exist.