Skip to Content
Idiomatic Rust
book

Idiomatic Rust

by Brenden Matthews
September 2024
Intermediate to advanced
256 pages
6h 40m
English
Manning Publications
Content preview from Idiomatic Rust

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 ...

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.
Start your free trial

You might also like

Rust in Action

Rust in Action

Tim McNamara
Effective Rust

Effective Rust

David Drysdale
The Rust Programming Language, 2nd Edition

The Rust Programming Language, 2nd Edition

Steve Klabnik, Carol Nichols

Publisher Resources

ISBN: 9781633437463Supplemental ContentPublisher SupportOtherPublisher WebsiteSupplemental ContentPurchase Link