munge
makes it easy to initialize MaybeUninit
s.
Just use the munge!
macro to destructure MaybeUninit
s the same way you'd destructure a value.
Initialize all the fields, then call assume_init
to unwrap it.
munge
has no features and is always #![no_std]
.
```rust use { ::core::mem::MaybeUninit, ::munge::munge, };
pub struct Example { a: u32, b: (char, f32), }
let mut mu = MaybeUninit::
munge!(let Example { a, b: (c, mut f) } = mu); asserteq!(a.write(10), &10); asserteq!(c.write('x'), &'x'); assert_eq!(f.write(3.14), &3.14); f = &mut MaybeUninit::uninit();
// SAFETY: mu
is completely initialized.
let init = unsafe { mu.assumeinit() };
asserteq!(init.a, 10);
asserteq!(init.b.0, 'x');
asserteq!(init.b.1, 3.14);
```