std-method
Pin::get_mut: mutable access for Unpin
Recover ordinary mutable access through a pinned mutable reference when its target is Unpin. Do not remove the bound from a generic function: it is part of the safe API. Expected stdout (not executed): [1, 2, 3] Common mistake: Calling get_mut for a non-Unpin target to bypass pinning.
Formal Syntax & Structure
rust syntaxrust
p.get_mut() -> &mut T where T: UnpinWorking Example
Example Snippetrust
fn main() { use std::pin::Pin; let mut data = vec![1, 2]; let p = Pin::new(&mut data); p.get_mut().push(3); println!("{:?}", data);}