macro_rules! unsafe_unpinned {
($v:vis $f:ident: $t:ty) => { ... };
}
Expand description
An unpinned projection of a struct field.
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.
Note that borrowing the field multiple times requires using .as_mut()
to
avoid consuming the Pin
.
use mulch::unsafe_unpinned;
use core::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();
}
}