macro_rules! get_mut {
($compact:expr, $variant:path) => { ... };
}
Expand description
Mutably borrows a variant from Compact
.
It requires the type of that variant implements FieldDerefMut
.
ยงExamples
use enum_ptr::{get_mut, Compact, EnumPtr};
#[derive(EnumPtr)]
#[repr(C, usize)]
enum Foo {
A(Box<i32>),
B(Box<u32>),
}
let mut foo: Compact<_> = Foo::A(Box::new(1)).into();
assert_eq!(get_mut!(foo, Foo::A), Some(&mut 1));
assert_eq!(get_mut!(foo, Foo::B), None);