macro_rules! unsafe_unpinned {
    ($f:tt: $t:ty) => { ... };
}
Expand description

An unpinned projection of a struct field.

Safety

This macro is unsafe because it creates a method that returns a normal non-pin reference to the struct field. It is up to the programmer to ensure that the contained value can be considered not pinned in the current context.

Example

use pin_utils::unsafe_unpinned;
use std::pin::Pin;

struct Bar;
struct Foo {
    field: Bar,
}

impl Foo {
    unsafe_unpinned!(field: Bar);

    fn baz(mut self: Pin<&mut Self>) {
        let _: &mut Bar = self.field(); // Normal reference to the field
    }
}

Note: borrowing the field multiple times requires using .as_mut() to avoid consuming the Pin.