DEV Community

Cover image for Pinning - Asynchronous Programming in Rust: Why, What, and How
I am a Programmer
I am a Programmer

Posted on

Pinning - Asynchronous Programming in Rust: Why, What, and How

The Why, What, and How of Pinning in Rust

With the Future trait stabilized and async/await coming soon, many more people are being exposed to the Pin type and its sibling trait Unpin. In this video, we dive deep into what these types are, why they are needed, how they work, and how to use them. We also dig into the connection to Futures and async/await, and discuss how you safely move from old code that does not use pinning to new code that does.

This is pretty dense and subtle material, but hopefully serves as a good and thorough overview of pinning in Rust. If you want to know how it all fits together, this stream probably has you covered! To help you navigate, here are the major transition points:

0:03:50 — What's the problem we're trying to solve?
0:28:19 — How does pinning help?
0:31:55 — What is Unpin?
0:35:14 — Working with pinned types
0:44:20 — An example of implementing Future
0:51:02 — Pin::new vs Pin::new_unchecked
0:59:16 — The problem with Drop
1:03:13 — Quick recap
1:07:26 — Why impl Unpin is safe
1:12:34 — Structural pinning
1:30:14 — The curious case of Box::pin
1:50:49 — Avoiding unsafe with pin-project
2:04:59 — Why is Pin::set okay?
2:08:03 — Pinning beyond Future
2:12:30 — Some quick questions
2:17:02 — Real-world examples of transitioning to Pin in tower
2:26:34 — pin-project and Drop
2:34:17 — Q&A!

Top comments (0)