std-type
Pin<P>: pinning pointer wrapper
The generic parameter is a pointer type, such as a mutable reference or Box. Pin limits access to the target according to its Unpin contract. A shared pinned reference allows observation but not arbitrary mutation. Expected stdout (not executed): 7 Common mistake: Writing Pin<Note> instead of using a suitable pointer type.
Formal Syntax & Structure
rust syntaxrust
pub struct Pin<Ptr> { /* private fields */ }Working Example
Example Snippetrust
fn main() { use std::{marker::PhantomPinned, pin::Pin}; struct Note { value: u32, _pin: PhantomPinned } let owned: Pin<Box<Note>> = Box::pin(Note { value: 7, _pin: PhantomPinned }); let view: Pin<&Note> = owned.as_ref(); println!("{}", view.get_ref().value);}