8 Iterators and closures

This chapter covers

  • Using method chaining to call one method after another after another
  • Using iterators, which are the most convenient way to work with collections
  • Using closures, which are functions that don’t need names and can capture variables in their scope

In this chapter, we’re going to see a lot of Rust’s functional style, which is based on expressions. This style lets you use a method that gives an output, that output becomes the next method’s input, and you repeat until you have the final output that you want. It works like a chain of methods, which is why people call it method chaining. Method chaining is a lot of fun once you get used to it; it lets you do a lot of work with not very much code. Iterators ...

Get Learn Rust in a Month of Lunches now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.