7
Understanding Iterators
The next stop on our tour of the Rust standard library is the iterator API. We know about iterators in C++ already, which we can use to iterate, or step one by one through the elements of the container, usually while performing an operation of some sort on them. While Rust iterators share the same name as C++ iterators, they end up being implemented quite differently. Rust's iterators are actually much closer to ranges, which were introduced in C++20.
In this chapter, we'll learn about the design of the Rust iterator library, the structures, functions, and traits that make up the iterator API, and how they compare to more traditional ways of looping through the elements of our containers.
In this chapter, we're going ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access