Rust 语言入门 Introduction to Rust

理解 async/await

rustc 编译器遇到 async 函数时, 会在内部生成对应的状态机代码 (state machine), 这个状态机会实现 Future trait.

async 表达式

async 函数

展开 async 函数

await 表达式

展开 await 表达式

参考

  • Understanding Async Await in Rust: From State Machines to Assembly Code
  • Nested async/await in Rust: Desugaring and assembly
  • Rust async/await: Async executor