Skip to main content

expect_expr_variant

Macro expect_expr_variant 

Source
macro_rules! expect_expr_variant {
    ($node:expr, $variant:path, $expr_name:literal $(,)?) => { ... };
}
Available on crate feature proto only.
Expand description

Open the outer PhysicalExprNode and assert it carries the expected ExprType variant, returning the inner payload (auto-derefs through Box) or bailing with an Internal error.

Every try_from_proto starts with the same six-line match:

let try_cast = match &node.expr_type {
    Some(protobuf::physical_expr_node::ExprType::TryCast(x)) => x.as_ref(),
    _ => return internal_err!("PhysicalExprNode is not a TryCastExpr"),
};

With this macro that collapses to:

let try_cast = expect_expr_variant!(
    node,
    protobuf::physical_expr_node::ExprType::TryCast,
    "TryCastExpr",
);

Pass the variant as a :: path so the macro stays agnostic to how the caller imports the proto types.