From: Benno Lossin <y86-dev@xxxxxxxxxxxxxx>
The `stack_pin_init!` macro allows pin-initializing a value on the
stack. It accepts a `impl PinInit<T, E>` to initialize a `T`. It allows
propagating any errors via `?` or handling it normally via `match`.
Signed-off-by: Benno Lossin <y86-dev@xxxxxxxxxxxxxx>
---
+#[macro_export]
+macro_rules! stack_pin_init {
+ (let $var:ident $(: $t:ty)? = $val:expr) => {
+ let mut $var = $crate::init::__internal::StackInit$(::<$t>)?::uninit();
+ let mut $var = {
+ let val = $val;
+ unsafe { $crate::init::__internal::StackInit::init(&mut $var, val) }
+ };
+ };
+ (let $var:ident $(: $t:ty)? =? $val:expr) => {
+ let mut $var = $crate::init::__internal::StackInit$(::<$t>)?::uninit();
+ let mut $var = {
+ let val = $val;
+ unsafe { $crate::init::__internal::StackInit::init(&mut $var, val)? }
+ };
+ };
+}