expression

Pin projection and structural pinning

Projection exposes a field through a pin. Whether a field must remain pinned is a design invariant of the outer type, not a rule inferred solely from its field type. Manual unchecked projection requires reviewing field moves, destruction, Unpin and layout. The safe example exposes only an ordinary shared field reference, not a structural mutable projection. Expected stdout (not executed): 7 Common mistake: Assuming a field can always be projected with map_unchecked_mut without a safety argument.

Formal Syntax & Structure

rust syntaxrust
Pin<&mut Outer> -> Pin<&mut Field> (when contract permits)

Working Example

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