trait
Unpin: pinning-independent types
Unpin indicates that the type does not depend on pinning restrictions. It is not a requirement for using a pinned value, nor a guarantee that a type is Copy. A value of a non-Unpin type may still move before it becomes pinned. Expected stdout (not executed): old new Common mistake: Assuming Unpin means Copy, or that a non-Unpin value can never move.
Formal Syntax & Structure
rust syntaxrust
pub auto trait Unpin {}Working Example
Example Snippetrust
fn main() { use std::{pin::Pin, mem}; fn replace<T: Unpin>(p: Pin<&mut T>, next: T) -> T { mem::replace(p.get_mut(), next) } let mut text = String::from("old"); let old = replace(Pin::new(&mut text), String::from("new")); println!("{old} {text}");}