Skip to main content

2 docs tagged with "iterator"

View all tags

Iterating over Collections

In the previous article, we introduced the for loop and used it to iterate over a range of numbers. The true power of for loops, however, comes from their ability to iterate over collections like arrays, vectors, and more. This is the most common and idiomatic way to work with collections in Rust.

Iterating over Collections: The `Iterator` Trait

We've seen how to use for loops to iterate over collections. But how does it actually work? The magic behind for loops is the Iterator trait. In this article, we'll take a closer look at this trait and the different ways you can create an iterator from a collection.