Unpin trait
Unpintype allows types to move freely, even when they’re wrapped by aPin- Most types implement
Unpin, because it is an “auto trait” auto traitbehavior can be changed:!Unpintypes must never move- Types containing a
PhantomPinnedfield do not implementUnpinby default
Explain that when a trait implements Unpin, the pinning behavior of Pin<Ptr>
does not get invoked. The value is free to move.
Explain that almost all types implement Unpin; automatically implemented by
the compiler.
Types implementing Unpin are saying: ‘I promise I have no self-references, so
moving me is always safe.’
Ask: What types might be !Unpin?
- Compiler-generated futures
- Types containing a
PhantomPinnedfield - Some types wrapping C++ objects
!Unpin types cannot be moved once pinned