Pin and self-referential structs in Rust
Pin is the type that makes people bounce off async Rust. It's not ceremony for
its own sake — it's how the language keeps self-referential structs (most async
state machines) from moving in memory while pointers inside them still point inward.
The problem
1234
If Bad moved, ptr would dangle. Async futures often embed pointers into their
own stack frame — same issue, bigger scale.
Pin breaks the move
Pin<P> promises not to move the pointee (unless Unpin). The compiler then allows
safe APIs that rely on a stable address.
Most types are Unpin — ordinary structs move freely. Pin matters for generated future
state machines and manual self-referential code. You'll feel it in async traits and
some stream adapters long before you write Pin yourself.
Practical guidance
For the concurrency story that makes all this matter, start with lock-free part one.