Skip to main content

define_enum_as_methods

Macro define_enum_as_methods 

Source
macro_rules! define_enum_as_methods {
    ($enum_type:ident, $(($variant:ident, $method:ident, $node_type:ty)),* $(,)?) => { ... };
}
Expand description

Generate a macro for the as_xxx method for PlanNodeEnum

ยงExamples

use linkrs_query::define_enum_as_methods;

enum MyPlanEnum {
    Start(i32),
    Project(i32),
}

define_enum_as_methods! {
    MyPlanEnum,
    (Start, as_start, i32),
    (Project, as_project, i32),
}

let node = MyPlanEnum::Start(42);
assert_eq!(node.as_start(), Some(&42));
assert!(node.as_project().is_none());