Rust’s Pin, Explained for C++ Folks

April 9, 2026
Detailed close-up of a safety pin attached to textured blue denim fabric.
Photo by Marek Ruczaj on Pexels

The puzzle

It has been reported that Pin is pretty important for Rust’s recently released async/await features, yet the docs left one reader scratching their head. The core confusion starts with Unpin — why is everything Unpin by default? Isn’t that like putting a “you can ignore this” sticker on a seatbelt? The author walks through the official rules for constructing a Pin and fixates on one line: you must not be able to get a &mut to the pinned target and then move out of it (think mem::swap or mem::replace). Why is moving via a mutable reference such a cardinal sin? Good question.

C++ moves vs. Rust moves — where the light bulb went on

If you come from C++, your mental model of “move” is a user-defined operation: move ctor runs, leaves the moved‑from object in some valid-but-unspecified state, maybe just a memcpy. That makes swapping elements in a container feel straightforward — just invoke moves and be done. Rust behaves differently. The compiler knows when a value is moved and can reuse its storage; after a move, the old slot can be overwritten without leaving a visible “husks.” The author even toys with unsafe examples — the undefined behavior allegedly printed “1” in one run — to show the compiler will reuse stack space. That’s the emotional pivot: moves in Rust aren’t just an operation you call, they’re a semantic event the compiler tracks and exploits.

So why does Pin matter (and why C++ devs should care)?

Pin prevents that compiler-friendly reordering by promising a value will never be moved in memory, which matters when you build self-referential types (common in async state machines and futures). In C++, you’d solve this by carefully writing move constructors; in Rust, Pin plus careful unsafe invariants closes the gap: it stops the compiler from doing the very optimizations that would break internal pointers. The takeaway is neat and practical — once you understand that Rust’s moves are a compile-time fact rather than just a runtime operation, Pin stops feeling like a magic trick and starts to look like a necessary safety leash for certain idioms in async Rust. Want to dig deeper? The original walkthrough does the heavy lifting with examples and is worth a read.

Sources: dpzmick.com, Lobsters