realloc_box_enum

Macro realloc_box_enum 

Source
macro_rules! realloc_box_enum {
    ($value:expr, {
        $target_variant:pat => Box::new($extracted:ident) => $target:expr,
        $other_variant:pat => $other:expr,
    }) => { ... };
}
Expand description

ยงExample

enum Value {
    One(BigValue1),
    Two(BigValue2),
}

struct BigValue1([u32; 10]);

struct BigValue2([u32; 7]);

fn convert_to_one(value: Box<Value>) -> Option<Box<BigValue1>> {
    realloc_box_enum!(value, {
        Value::One(value) => Box::new(value) => Some(value),
        _ => None,
    })
}