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

Initialize and pin a type directly on the stack.

§Examples

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

struct Bar {
    x: u32,
}

stack_try_pin_init!(let foo: Foo = try_pin_init!(Foo {
    a <- CMutex::new(42),
    b: Box::try_new(Bar {
        x: 64,
    })?,
}? FooError));
let foo = foo.unwrap();
println!("a: {}", &*foo.a.lock());
#[pin_data]
struct Foo {
    #[pin]
    a: CMutex<usize>,
    b: Box<Bar>,
}

struct Bar {
    x: u32,
}

stack_try_pin_init!(let foo: Foo =? try_pin_init!(Foo {
    a <- CMutex::new(42),
    b: Box::try_new(Bar {
        x: 64,
    })?,
}? FooError));
println!("a: {}", &*foo.a.lock());

§Syntax

A normal let binding with optional type annotation. The expression is expected to implement PinInit/Init. This macro assigns a result to the given variable, adding a ? after the = will propagate this error.