The Why, What, and How of Pinning in Rust
Jon Gjengset3 HN recommenders · recommended in 3 months, 2021–2026
tutorial · advanced · evergreen · 2021–2026 on HN
Jon Gjengset's long live-coding stream explains Rust's Pin and Unpin types: why they exist, how they work, and how they connect to futures and async/await. It also covers moving from pre-pinning code to the new model.
HN treats it as the definitive resource for understanding Pin semantics and lists it among async Rust learning materials.
Up next
5 mo on HNCoding Adventure: Ant and Slime Simulations
Sebastian Lague
6 HN recommender · 2021–2024
3 mo on HNBlack Hat USA 2013 - OPSEC failures of spies
Black Hat
3 HN recommender · 2016–2019
2 mo on HNArithmetic, Population and Energy - FULL LENGTH
kip399
3 HN recommender · 2016–2024
4 mo on HNThe Most Misunderstood Concept in Physics
Veritasium
5 HN recommender · 2023–2024
6 mo on HNCanceling | ContraPoints
ContraPoints
7 HN recommender · 2020–2025
2 mo on HNCrust of Rust: async/await
Jon Gjengset
2 HN recommender · 2023–2026
11 mo on HNCppCon 2015: Andrei Alexandrescu “std::allocator...”
CppCon
7 HN recommender · 2017–2025
12 mo on HNLexical Scanning in Go - Rob Pike
GoogleFOSSSydney
13 HN recommender · 2012–2025
10 mo on HNCppCon 2017: Matt Kulukundis “Designing a Fast, Efficient, Cache-friendly Hash Table, Step by Step”
CppCon
9 HN recommender · 2018–2026
9 mo on HNRustConf 2018 - Closing Keynote - Using Rust For Game Development by Catherine West
Rust Programming Language
9 HN recommender · 2018–2023
10 mo on HNCppCon 2016: Jason Turner “Rich Code for Tiny Computers: A Simple Commodore 64 Game in C++17”
CppCon
13 HN recommender · 2016–2024
9 mo on HNIdeas about a new programming language for games.
Jonathan Blow
7 HN recommender · 2014–2025
3 comments from Hacker News
Jon Gjengset's stream on pin/unpin is invaluable for understanding Pin semantics: ▶ this video But the 10000 ft view is: Pin lets you tell Rust to never ever move a piece of memory. This is almost always done because the piece of memory has pointers into itself (it's self referencial) which would be come invalid if moved.
there is a chapter on async in comprehensive rust and rustbook which ought to bring you up to speed there is the async book but it is largely unfinished you can watch John Gjengset's crust of rust async, decrusting tokio, and why what, and how of pinning in rust then there are tokio-lessons and tokio tutorial which teach how to use tokio runtime and there are also good blogposts by phil-oop and rose wright on how async works link link link link link ▶ this video link link link link
Let's assume for a moment self-referential references were allowed. Let's further say we have such a struct containing self-referential references and we move it. Moving actually moves things in memory, including the thing those references reference. This means the references now point at the old and now incorrect location. Accessing them would trigger undefined behavior. Self-referencing is only acceptable, if the struct is guaranteed not to move. Rust does provide a mechanism to provide such a guarantee with std::pin but outside of async code, you probably don't want to be using it. std::pin: link If you're curious about pinning and have a few hours to spare, ▶ this video is a great video that explains it in detail.