Macro pin_utils::unsafe_pinned[][src]

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

A pinned projection of a struct field.

Safety

To make using this macro safe, three things need to be ensured:

Example

use pin_utils::unsafe_pinned;
use std::marker::Unpin;
use std::pin::Pin;

struct Foo<T> {
    field: T,
}

impl<T> Foo<T> {
    unsafe_pinned!(field: T);

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

impl<T: Unpin> Unpin for Foo<T> {} // Conditional Unpin impl

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