“Rust does a great job of documenting its features so these questions are usually already answered.”
Asynchronous Programming in Rust 由 Rust 异步工作组维护,是 Rust 官方的 async/await 指南,讲解 Future、执行器、Pin、Stream 以及异步代码的组织方式。书以解释概念为主,配有示例,帮助理解 Rust 的异步模型和其他语言的差别。它不是 Rust 入门书,更适合已学过 Rust 基础的人;部分章节仍不完整,需要和 tokio 等运行时文档配合。
HN 上的人常引用它来解释 Rust 的 async 为什么存在、Pin 是什么、Future 是惰性的这些要点,也用来区分 reactor 和 runtime。同时有评论指出它不够完整,不同执行器之间难以互通这类问题书里没说透。
已掌握 Rust 基础、想写异步代码的开发者
怎么读
由 Claude 根据这本书和 HN 上的说法整理,可能有错- 1先读为什么要 async 的部分,建立整体印象
- 2Pin 一章不好懂,可先看后面再回头读
- 3配合 tokio 或其他运行时的文档一起读
- 4自己动手写一个小型异步服务来练手
HN 书评
推荐在前,同类按时间 · 每本最多保留 20 条,统计用全部提及 · 作者本人贴的不算“The tokio alpha docs and the async book[0] has some info, but both are a bit incomplete.”
“For more on how async in Rust works, I'd invite you to read the actual manual on the subject (linked from the announcement): Asynchronous Programming in Rust”
“But if you are curious, this chapter explains it pretty good:”
“There are also some resources that are still incomplete, like the async book”
“So I would still start at Asynchronous Programming in Rust”
看全部 20 条 →
“[This page] gives some nice details about the difference”
“Is missing, somewhat ironic?”
“(What is Pin? ref Asynchronous Programming in Rust)”
“Visiting Asynchronous Programming in Rust I don't see any mentions of neither C# nor JS.”
“Async/await in Rust compiles down to a state machine (and to my understanding, uses generators under the hood):”
“Even the async book[1] says:”
“I took an example of a server straight from the Rust async book, and to my surprise, it performed very well for a long time serving real internet requests”
“The rust async/.await primer [2] offers the reader the seemingly helpful futures::executor::block_on, but basically no two executors can interact”
“("Futures are inert in Rust and make progress only when polled"[1])”
“For example, recursive functions require dynamic allocation in an async context because the async state must be statically sized. See Asynchronous Programming in Rust”
“Currently in Rust async/await generators discussion has been put on hold as being a hot topic”
“In the async book from Rust [1]:”
“Rust uses async/await based concurrency: Asynchronous Programming in Rust”
“See for example the discussion of stack pinning here: Asynchronous Programming in Rust”