12 More on closures, generics, and threads

This chapter covers

  • Closures in functions
  • impl Trait as another way to use generics
  • Arc, which is like Rc but thread-safe
  • Scoped threads, threads that only live inside a scope
  • Using channels to send messages, even across threads

This chapter is a bit like the last one: lots of new ideas that are tricky to understand at first. The first section on closures as arguments in functions is probably the hardest but continues what we learned in the last chapter about the three types of closures. Fortunately, the rest of the chapter is made up of similar things to what you’ve learned before. impl Trait is like regular generics but easier to write, Arc is like Rc, and scoped threads are like threads but easier ...

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.