Rust NYC: Jon Gjengset - Demystifying unsafe code
Why Hacker News recommends it
HN recommends it as the best calm explanation of unsafe Rust, from a speaker commenters trust on the topic.
What it is
Jon Gjengset's Rust NYC talk explaining what `unsafe` in Rust actually means, why it is dangerous, and why it is sometimes necessary. He works through the Rustonomicon to separate fair concerns from overblown ones.
Recommended by 2 HN commenters across 2 different months, 2020 to 2024.
What Hacker News said
Recommends Sammi · 2020-04 · on “How to speed up the Rust compiler in 2020”
There's a great new talk by on Gjengset on youtube that tackles just this question: Rust NYC: Jon Gjengset - Demystifying unsafe code [this video]
Recommends saghm · 2024-12 · on “Compiling C to Safe Rust, Formalized”
While I might agree that it's easy if you use a reference counter, this is not going to be as performant as the typical linked list written in C, which is why the standard library uses unsafe for its implementation of stuff like this. If it were "easy" to just write correct `unsafe`, then it would be easy to do it in C as well. Note that the converse to this isn't necessarily true! People I trust way more to write unsafe Rust code than me than me have argued that unsafe Rust can be harder than writing C in some ways due to having to uphold certain invariants that don't come up in C. While there are a number of blog posts on the topic that anyone interested can probably find fairly easily by
Cites ibraheemdev · 2021-05 · on “The Rustonomicon”
The rustnomicon is a very good resource. It's less of "the unsafe book" and more "the advanced book", covering lower-level details and advanced concepts that aren't touch on by the book. One gripe I have is that it kind of pushes the idea that unsafe is bad and evil, which is not true at all: > The Dark Arts of Unsafe Rust > THE KNOWLEDGE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF UNLEASHING INDESCRIBABLE HORRORS THAT SHATTER YOUR PSYCHE AND SET YOUR MIND ADRIFT IN THE UNKNOWABLY INFINITE COSMOS. I know it's a joke, and I laughed when I first read it. Unsafe is dangerous and requires care, but unsafe == evil is defini