按年被提到
20152025 · 25 次2026
开源书›编程语言·No.36·简称 Nomicon

The Rustonomicon

Rustonomicon:Rust 不安全代码指南
The Rust Project

讲清 unsafe Rust 的规则、内存表示与常见陷阱的官方进阶指南

免费阅读 ↗
被推荐 · 146 人首次 2015-10-30 · 最近 2026-08-27许可证 MIT / Apache 2.0
146不同的人
91活跃月份
25有推荐的月份
157讨论串

Rust 官方项目写的进阶文档,讲 unsafe Rust 的工作方式:什么是安全、什么需要自己保证,以及数据在内存里的表示、子类型和变型(variance)、Send 与 Sync 等。其中有一部分带读者从头实现 Vec 等数据结构,是不错的实战材料。和 The Rust Programming Language 不同,它假定读者已会写 Rust,专讲底层细节。

HN 为什么推荐它

HN 上的人把它当作学习 unsafe Rust 和理解 Rust 安全保证的首选资料,常被引用来解释数据竞争、变型、PhantomData、FFI 和并发;也有人批评它更新慢、还有一些未写完的 TODO。

难度 4 / 5约 20 小时开放许可
适合谁

已会写 Rust、想弄懂 unsafe 的开发者

读之前最好知道
1Rust 基础与所有权(ownership)
2C 语言指针
3内存布局基础

怎么读

由 Claude 根据这本书和 HN 上的说法整理,可能有错
  1. 1先学完一本 Rust 入门书,再来读这份文档
  2. 2从安全与不安全的边界和内存表示读起,建立整体概念
  3. 3跟着实现 Vec 的部分动手写一遍,比只看更有效
  4. 4变型、PhantomData 这类概念当作查阅用的参考,反复回看

HN 书评

推荐在前,同类按时间 · 每本最多保留 20 条,统计用全部提及 · 作者本人贴的不算
强烈推荐cyber_kinetist · 2022-05

“I highly recommend anyone trying out Rust for the safety guarantees to take a look at the Rustonomicon”

强烈推荐想靠安全保证上手 Rust 的人读它
Will Hare replace C? Or Rust? Or Zig? Or anything else?原评论 ↗
推荐Munksgaard · 2016-05

“Rust prevents _data races_, but not _race conditions_. You can read more in the Rustonomicon here: The Rustonomicon”

拿它说明 Rust 防止 data race 但不防止 race condition
The Path to Rust原评论 ↗
推荐Manishearth · 2017-02

“(链接) and The Rustonomicon are pretty good resources about writing unsafe Rust.”

推荐它作为编写 unsafe Rust 的好资料
Regex: badly needs fuzzing原评论 ↗
推荐geofft · 2017-08

“Here's a doc on how to write such a function yourself, and includes the (actual) source code for split_at_mut:”

指向它,讲如何自己写 split_at_mut 这类函数并附真实源码
Rust: Not So Great For Codec Implementing原评论 ↗
推荐andrewflnr · 2017-09

“If you want to write the library, you may want the Rustonomicon: The Rustonomicon.”

建议想写这个库的人读它,学用 unsafe Rust 实现数据结构
Announcing Rust 1.20原评论 ↗
推荐notriddle · 2018-09

“It's surprising how many things in that book don't have anything to do with unsafe per se.”

指出书里很多内容与 unsafe 本身无关,如 subtype variance
Falling in love with Rust原评论 ↗
看全部 20 条 →
推荐ZirconiumX · 2019-03

“You should read [1] to understand how Rust achieves this.”

让人读它来理解 Rust 如何做到避免 data race
Fuchsia OS Introduction原评论 ↗
推荐oconnor663 · 2019-04

“This section of the nomicon goes into more detail: The Rustonomicon”

指向其中一节,详述 unsafe 代码对所在模块的影响
Orange_slice: Research Kernel and Hypervisor in Rust原评论 ↗
推荐steveklabnik · 2019-10

“The Rustonomicon is a good starting place for learning about this.”

推荐它作为了解 unsafe Rust 的好起点
How to not rewrite it in Rust原评论 ↗
推荐glandium · 2020-08

“The one thing I can't get to stick in my brain is variance. Every time, I need to go back to The Rustonomicon”

说自己总记不住 variance,每次都回头查它
Rust 1.46原评论 ↗
推荐heavyset_go · 2021-09

“It might help to better understand the motivations behind unsafe Rust by reading some of The Rustonomicon[1].”

建议读它来理解 unsafe Rust 背后的动机
Maintain It with Zig原评论 ↗
推荐chlorion · 2022-02

“There is a section where you implement Vec and some other data structures from scratch!”

指出其中有从零实现 Vec 等数据结构的章节
‘Zero-click’ hacks are growing in popularity原评论 ↗
推荐remram · 2022-04

“Check out also the "Rust considers it safe to" section of The Rustonomicon”

推荐看其中“Rust considers it safe to”一节
What Is Rust's Unsafe? (2019)原评论 ↗
推荐Ygg2 · 2022-09

“PhantomData is just a type marker that has no purpose other than help compiler. See The Rustonomicon”

引它说明 PhantomData 只是给编译器用的类型标记
Rust 2024 the Year of Everywhere?原评论 ↗
推荐jmillikin · 2022-10

“the Rustonomicon has often answered my questions about more advanced topics (FFI, concurrency).”

说它常解答自己关于 FFI、并发等进阶问题
Ask HN: Recommended Rust Resources?原评论 ↗
推荐gridspy · 2022-11

“I found it useful to understand the underlying data representation in memory. For instance The Rustonomicon”

说它帮自己理解数据在内存中的底层表示
The pool of talented C++ developers is running dry原评论 ↗
推荐lynndotpy · 2022-12

“The Rustonomicon (WIP) made Rust things click in a way that really benefitted me: The Rustonomicon”

说这本(未完成的)书让 Rust 的许多概念豁然开朗
Ask HN: What is the best thing you read in 2022?原评论 ↗
推荐dagmx · 2024-08

“It’s probably more correct if I say that data types themselves are thread safe or not.”

指向它,了解 Send 和 Sync 等线程安全概念
Rust solves the problem of incomplete Kernel Linux API docs原评论 ↗
推荐simonask · 2024-10

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

推荐它作为 unsafe 代码能做什么的不错入门,内容至今没变
Smart pointers for the kernel原评论 ↗
批评nyanpasu64 · 2021-05

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

批评它很久没有新发布,有未发布的提交和散落的 TODO
The Rustonomicon原评论 ↗