std-method
Pin::into_ref: consume a mutable pin as shared
Convert a pinned mutable reference to a pinned shared reference without extending the borrow lifetime or moving the pointee. Unlike as_ref, the conversion consumes the mutable pin handle. Expected stdout (not executed): 7 Common mistake: Expecting to keep using the consumed mutable pin handle.
Formal Syntax & Structure
rust syntaxrust
p.into_ref() -> Pin<&T>Working Example
Example Snippetrust
fn main() { use std::{marker::PhantomPinned, pin::Pin}; struct Note { value: u32, _pin: PhantomPinned } let p = std::pin::pin!(Note { value: 7, _pin: PhantomPinned }); let shared = p.into_ref(); println!("{}", shared.value);}