8 State machines, coroutines, macros, and preludes

This chapter covers

  • Using traits to construct state machines
  • Writing pausable functions with coroutines
  • Implementing procedural macros
  • Providing preludes to improve the usability of your crates

This chapter continues some of the themes from chapter 7 and builds on much of what we’ve learned in the book. We’ll start by discussing state machines and coroutines. Then we’ll introduce procedural macros, an advanced Rust feature that allows us to generate code at compile time. Last, we’ll discuss preludes, which are a commonly used Rust library pattern to improve usability.

Rust’s traits are powerful, and combined with generics, they let us build type-safe abstractions that allow us to guarantee ...

Get Idiomatic Rust 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.