Macro kernel::stack_try_pin_init
source · 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: Mutex<usize>,
b: Box<Bar>,
}
struct Bar {
x: u32,
}
stack_try_pin_init!(let foo: Result<Pin<&mut Foo>, AllocError> = pin_init!(Foo {
a <- new_mutex!(42),
b: Box::try_new(Bar {
x: 64,
})?,
}));
let foo = foo.unwrap();
pr_info!("a: {}", &*foo.a.lock());
ⓘ
#[pin_data]
struct Foo {
#[pin]
a: Mutex<usize>,
b: Box<Bar>,
}
struct Bar {
x: u32,
}
stack_try_pin_init!(let foo: Pin<&mut Foo> =? pin_init!(Foo {
a <- new_mutex!(42),
b: Box::try_new(Bar {
x: 64,
})?,
}));
pr_info!("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.