A Pin<P> ensures that the pointee of any pointer type P has a stable location in memory, meaning it cannot be moved elsewhere and its memory cannot be deallocated until it gets dropped. We say that the pointee is “pinned”.
I introduced the concept of an Anchor: the idea of an anchor was that once something was inside an anchor, there is no way to get it out again. You can’t move out of an anchor, and it is unsafe to get a mutable reference to the thing in it.
A new marker trait called Unpin has been added to std. Like Send and Sync, it is an auto trait: it doesn’t define any methods, and types implement Unpin by default. A type that implements Unpin is safe to move out of the new Pin reference type. Unpin is not implemented for self-referential generators, making it unsafe to move them out of the Pin reference.
Recently, a new API for “pinned references” has landed as a new unstable feature in the standard library. The purpose of these references is to express that the data at the memory it points to will not, ever, be moved elsewhere. @withoutboats has written about how this solves a problem in the context of async IO. In this post, we take a closer, more formal look at that API: We are going to take a stab at extending the RustBelt model of types with support for pinning.