Macro impl_op2_opt

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

Defines a macro for implementing a two-operand operation trait with optional evaluation.

This macro generates implementations for the Op2 trait for a specified type by providing a framework where specific pairs of input types can define conversion logic and evaluation. For each tuple of input types and a resulting type provided within the macro invocation, the macro matches on the value types and applies a provided closure f to corresponding elements of the input values. It utilizes the itertools::izip! macro to pair elements from both input lists, applying the transformation function f, and collecting the results into a new list. If the operation fails or an element cannot be converted, it uses a default value for the resulting type. The generated implementation returns a flag indicating whether the operation was successful for all elements and the new value. If the inputs do not match any specified type combinations, the operation returns false with a Null value. This approach facilitates the flexible application of operations over compatible pairings of types while maintaining robust default behavior.