std-method

Pin::as_mut: reborrow a pinned value

Reborrow when a method consumes a Pin<&mut T>. The owner remains available after each reborrow ends. This works even for non-Unpin targets; it is not permission to move them out. Expected stdout (not executed): 7 7 Common mistake: Passing the same consuming pin handle twice without reborrowing.

Formal Syntax & Structure

rust syntaxrust
p.as_mut() -> Pin<&mut T>

Working Example

Example Snippetrust
fn main() {    use std::{marker::PhantomPinned, pin::Pin};    struct Note { value: u32, _pin: PhantomPinned }    fn inspect(p: Pin<&mut Note>) { println!("{}", p.value); }    let mut p = Box::pin(Note { value: 7, _pin: PhantomPinned });    inspect(p.as_mut());    inspect(p.as_mut());}
Rust Reference