Rust Pin
(Jin Qing's Column, Sep., 2024)
From: https://doc.rust-lang.org/std/pin/index.html
Rust can pin data location in memory, that means its address can not be changed.
Pinned data guarantees the memory location is always valid.
Safe code can not move pinned data to another location.
Safe code users do not need to care about Pin.
- What's moving
- copy + ownership
- all values are movable
- assignment or function parameter
- mem::replace
- What's pinning
- until drop
- Address sensitivity
- some interface is relay on pinned state
- self-referenced type: Future
- leverage the type system
- Pin
- how Pin works
- restrict access to Ptr
- PhantomPinned
- Example types
- self-referential struct
- intrusive list
- Drop
- Projection and Structural Pinning