Macro get_ref

Source
macro_rules! get_ref {
    ($compact:expr, $variant:path) => { ... };
}
Expand description

Borrows a variant from Compact.

It requires the type of that variant implements FieldDeref.

ยงExamples

use enum_ptr::{get_ref, Compact, EnumPtr};

#[derive(EnumPtr)]
#[repr(C, usize)]
enum Foo {
    A(Box<i32>),
    B(Box<u32>),
}

let foo: Compact<_> = Foo::A(Box::new(1)).into();
assert_eq!(get_ref!(foo, Foo::A), Some(&1));
assert_eq!(get_ref!(foo, Foo::B), None);