Search⌘ K

IntoIterator

Explore how Rust's IntoIterator trait allows collections such as Vec to be converted into iterators. Understand the importance of this trait for writing ergonomic, readable code when using loops, and learn why Vec itself does not implement the Iterator trait directly.

We'll cover the following...

Here’s an important takeaway from our VecIter in the previous lesson: a Vec on its own doesn’t have enough information to be iterated over. We need to know the current position in the iteration, and a Vec doesn’t have that information. Therefore, it’s impossible to have an Iterator implementation for Vec. And sure enough, there is no such implementation available. We ...