macro_rules! stack_pin_init {
    (let $var:ident $(: $t:ty)? = $val:expr) => { ... };
    (let $var:ident $(: $t:ty)? =? $val:expr) => { ... };
}
Expand description

Initialize a type directly on the stack.

Examples

#[pin_data]
struct Foo {
    #[pin]
    a: CMutex<usize>,
    b: Bar,
}

#[pin_data]
struct Bar {
    x: u32,
}

let a = CMutex::new(42);

stack_pin_init!(let foo =? pin_init!(Foo {
    a <- a,
    b: Bar {
        x: 64,
    },
}));
let foo: Pin<&mut Foo> = foo;

Syntax

A normal let binding with optional type annotation. The expression is expected to implement PinInit. Additionally a ? can be put after the =, this will assign Pin<&mut T> to the variable instead of Result<Pin<&mut T>, E>.