std-method
Pin::new: safe wrapping for Unpin targets
Use Pin::new when the pointer target does not rely on pinning. This constructor does not move the underlying value into a new allocation. Expected stdout (not executed): 6 Common mistake: Expecting Pin::new to accept a mutable reference to every non-Unpin type.
Formal Syntax & Structure
rust syntaxrust
Pin::new(pointer) -> Pin<Ptr> where Ptr::Target: UnpinWorking Example
Example Snippetrust
fn main() { use std::pin::Pin; let mut count = 4; let mut p = Pin::new(&mut count); *p += 2; println!("{}", *p);}