macro_rules! munge {
(@field($ptr:ident) $field:tt) => { ... };
(@element($ptr:ident) $index:tt) => { ... };
(@parse_binding mut $name:ident $(,)?) => { ... };
(@parse_binding mut $name:ident, $($rest:tt)+) => { ... };
(@parse_binding $body:tt $(,)?) => { ... };
(@parse_binding $body:tt, $($rest:tt)+) => { ... };
(@parse_binding $first:tt $($rest:tt)+) => { ... };
(@bindings _) => { ... };
(@bindings ..) => { ... };
(@bindings $name:ident) => { ... };
(@bindings mut $name:ident) => { ... };
(@bindings { .. }) => { ... };
(@bindings { $field:ident $(,)? }) => { ... };
(@bindings { mut $field:ident $(,)? }) => { ... };
(@bindings { $field:ident, $($rest:tt)+ }) => { ... };
(@bindings { mut $field:ident, $($rest:tt)+ }) => { ... };
(@bindings { $field:ident: $($body:tt)+ }) => { ... };
(@bindings ( $($body:tt)+ )) => { ... };
(@bindings [ $($body:tt)+ ]) => { ... };
(@parse_field($ptr:ident, $field:ident, $value:ident) { $body:tt $(,)? }) => { ... };
(@parse_field($ptr:ident, $field:ident, $value:ident) { $body:tt, $($rest:tt)+ }) => { ... };
(@parse_field($ptr:ident, $field:ident, $value:ident) { $first:tt $($rest:tt)+ }) => { ... };
(@parse_field($ptr:ident, $index:tt, $value:ident) ( $body:tt $(,)? ) $indices:tt) => { ... };
(@parse_field($ptr:ident, $index:tt, $value:ident) ( $body:tt, $($rest:tt)+ ) $indices:tt) => { ... };
(@parse_field($ptr:ident, $index:ident, $value:ident) ( $first:tt $($rest:tt)+ ) $indices:tt) => { ... };
(@parse_field($ptr:ident, $index:tt, $value:ident) [ $body:tt $(,)? ] $indices:tt) => { ... };
(@parse_field($ptr:ident, $index:tt, $value:ident) [ $body:tt, $($rest:tt)+ ] $indices:tt) => { ... };
(@parse_field($ptr:ident, $index:ident, $value:ident) [ $first:tt $($rest:tt)+ ] $indices:tt) => { ... };
(@fields($ptr:ident, $value:ident) _) => { ... };
(@fields($ptr:ident, $value:ident) $field:ident) => { ... };
(@fields($ptr:ident, $value:ident) { .. }) => { ... };
(@fields($ptr:ident, $value:ident) { mut $field:ident $(,)? }) => { ... };
(@fields($ptr:ident, $value:ident) { $field:ident $(,)? }) => { ... };
(@fields($ptr:ident, $value:ident) { mut $field:ident, $($rest:tt)+ }) => { ... };
(@fields($ptr:ident, $value:ident) { $field:ident, $($rest:tt)+ }) => { ... };
(@fields($ptr:ident, $value:ident) { $field:ident: $($binding:tt)+ }) => { ... };
(@fields($ptr:ident, $value:ident) ( .. ) $indices:tt) => { ... };
(@fields($ptr:ident, $value:ident) ( $($binding:tt)* ) [ $index_first:tt $($index_rest:tt)* ]) => { ... };
(@fields($ptr:ident, $value:ident) ( $($body:tt)* )) => { ... };
(@fields($ptr:ident, $value:ident) [ .. ] $indices:tt) => { ... };
(@fields($ptr:ident, $value:ident) [ $($binding:tt)* ] [ $index_first:tt $($index_rest:tt)* ]) => { ... };
(@fields($ptr:ident, $value:ident) [ $($body:tt)* ]) => { ... };
(@fields($ptr:ident, $value:ident) $first:tt $($rest:tt)*) => { ... };
(@destructure { $($path:tt)* } $body:tt = $value:expr) => { ... };
(@destructure { $($path:tt)* } $first:tt $($rest:tt)*) => { ... };
(let $($tokens:tt)*) => { ... };
}
Expand description
Projects a MaybeUninit
type to its MaybeUninit
fields using destructuring.
Example
pub struct Example {
a: u32,
b: (char, f32),
}
let mut mu = MaybeUninit::<Example>::uninit();
munge!(let Example { a, b: (c, mut f) } = &mut mu);
assert_eq!(a.write(10), &10);
assert_eq!(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.assume_init() };
assert_eq!(init.a, 10);
assert_eq!(init.b.0, 'x');
assert_eq!(init.b.1, 3.14);