Macro impl_op3_opt

Source
macro_rules! impl_op3_opt {
    ($s:ident, $name:expr, $(($t1:ident, $t2:ident, $t3:ident) -> $rt:ident { $f:expr }),*) => { ... };
}
Expand description

A macro for implementing ternary operations with optional characteristics.

This macro, impl_op3_opt!, simplifies the process of defining implementations for the Op3 trait on a specified type (designated by $s). For each combination of argument types and return type specified, it generates the operation’s logic by defining the cost and try_eval methods for the Op3 trait.

In try_eval, the macro handles different matching patterns of input argument types. It uses pattern matching to destructure given values into tuples of variant types defined in $t1, $t2, and $t3. The evaluation iterates over combined elements of these tuples using the itertools::izip! macro, applying an expression $f on them. This produces an output optionally handled via a flag, which determines success. If any element evaluation yields None, the default value specified for the return type $rt is used instead. The resulting values are collected using galloc_scollect() into the expected result type wrapped in crate::value::Value::$rt. If none of the specified patterns match, the operation defaults to returning a false flag and a Value::Null.