std-method
Pin::as_ref and get_ref: shared observation
Borrow a pinned pointee for read-only observation. Shared access may still support interior mutability, but it does not provide an unrestricted mutable reference to the entire pointee. Expected stdout (not executed): 7 Common mistake: Confusing a shared reference with permission to move out a non-Copy field.
Formal Syntax & Structure
rust syntaxrust
p.as_ref() -> Pin<&T>; p.as_ref().get_ref() -> &TWorking Example
Example Snippetrust
fn main() { use std::{marker::PhantomPinned, pin::Pin}; struct Note { value: u32, _pin: PhantomPinned } let p = Box::pin(Note { value: 7, _pin: PhantomPinned }); let note = p.as_ref().get_ref(); println!("{}", note.value);}