“I highly recommend anyone trying out Rust for the safety guarantees to take a look at the Rustonomicon”
The Rustonomicon
讲清 unsafe Rust 的规则、内存表示与常见陷阱的官方进阶指南
Rust 官方项目写的进阶文档,讲 unsafe Rust 的工作方式:什么是安全、什么需要自己保证,以及数据在内存里的表示、子类型和变型(variance)、Send 与 Sync 等。其中有一部分带读者从头实现 Vec 等数据结构,是不错的实战材料。和 The Rust Programming Language 不同,它假定读者已会写 Rust,专讲底层细节。
HN 上的人把它当作学习 unsafe Rust 和理解 Rust 安全保证的首选资料,常被引用来解释数据竞争、变型、PhantomData、FFI 和并发;也有人批评它更新慢、还有一些未写完的 TODO。
已会写 Rust、想弄懂 unsafe 的开发者
怎么读
由 Claude 根据这本书和 HN 上的说法整理,可能有错- 1先学完一本 Rust 入门书,再来读这份文档
- 2从安全与不安全的边界和内存表示读起,建立整体概念
- 3跟着实现 Vec 的部分动手写一遍,比只看更有效
- 4变型、PhantomData 这类概念当作查阅用的参考,反复回看
HN 书评
推荐在前,同类按时间 · 每本最多保留 20 条,统计用全部提及 · 作者本人贴的不算“Rust prevents _data races_, but not _race conditions_. You can read more in the Rustonomicon here: The Rustonomicon”
“(链接) and The Rustonomicon are pretty good resources about writing unsafe Rust.”
“Here's a doc on how to write such a function yourself, and includes the (actual) source code for split_at_mut:”
“If you want to write the library, you may want the Rustonomicon: The Rustonomicon.”
“It's surprising how many things in that book don't have anything to do with unsafe per se.”
看全部 20 条 →
“You should read [1] to understand how Rust achieves this.”
“This section of the nomicon goes into more detail: The Rustonomicon”
“The Rustonomicon is a good starting place for learning about this.”
“The one thing I can't get to stick in my brain is variance. Every time, I need to go back to The Rustonomicon”
“It might help to better understand the motivations behind unsafe Rust by reading some of The Rustonomicon[1].”
“There is a section where you implement Vec and some other data structures from scratch!”
“Check out also the "Rust considers it safe to" section of The Rustonomicon”
“PhantomData is just a type marker that has no purpose other than help compiler. See The Rustonomicon”
“the Rustonomicon has often answered my questions about more advanced topics (FFI, concurrency).”
“I found it useful to understand the underlying data representation in memory. For instance The Rustonomicon”
“The Rustonomicon (WIP) made Rust things click in a way that really benefitted me: The Rustonomicon”
“It’s probably more correct if I say that data types themselves are thread safe or not.”
“The Rustonomicon [1] serves as a decent introduction to what you can or can't do in unsafe code, and none of that changed to my knowledge.”
“Sadly, IIRC the Nomicon hasn't seen a new release in a while (meaning there's unpublished Github commits at (链接) ), and there are some TODOs scattered throughout the document.”