"Pinning" is one of the harder concepts to wrap your head around when writing async Rust. The idea is that we can mark something as: "This won't change memory addresses from this point forward". This allows self-referential pointers to work, which are needed for async borrowing over await points. Though that's what it's useful for. In practice, how we use it is (generally) through one of three techniques:
- stack pinning 1: this puts an object on the stack and ensures it doesn't move.
- heap pinning: using Box::pin to pin a type on the heap to ensure it doesn't move. This is often used as an alternative to stack pinning.
- pin projections: convert from coarse: "This whole type is pinned" to more fine-grained: "Actually only these fields on the type need to be pinned".
Source: Safe Pin Projections Through View Types, an article by Yoshua Wuyts.