std-type
PhantomPinned: opt out of automatic Unpin
A field of this marker type prevents automatic Unpin for an ordinary containing struct. It does not create self-references or pin an instance on its own. The example moves the unpinned value before establishing pinning. Expected stdout (not executed): 7 Common mistake: Thinking PhantomPinned alone pins a newly constructed value.
Formal Syntax & Structure
rust syntaxrust
pub struct PhantomPinned;Working Example
Example Snippetrust
fn main() { use std::{marker::PhantomPinned, pin::Pin}; struct Note { value: u32, _pin: PhantomPinned } let before = Note { value: 7, _pin: PhantomPinned }; let moved = before; let pinned = Box::pin(moved); println!("{}", pinned.value);}