match_commutative/
commutative.rs

1#[macro_export]
2macro_rules! match_commutative {
3    (
4        $operant1_expr:expr,
5        $bin_op_expr:expr,
6        $operant2_expr:expr,
7        $( $operant1:pat, $bin_op:pat, $operant2:pat $(if $if_expr:expr)? => $block_to_execute:block ), +
8        $(non_commut { $( $operant1_non_commut:pat, $bin_op_non_commut:pat, $operant2_non_commut:pat $(if $if_expr_non_commut:expr)? => $block_to_execute_non_commut:block ), + })?
9    ) => {
10        {
11            match ($operant1_expr, $bin_op_expr, $operant2_expr) {
12                $(
13                    ($operant1, $bin_op, $operant2) | ($operant2, $bin_op, $operant1) $(if $if_expr)? => $block_to_execute
14                )+
15                $($(
16                    ($operant1_non_commut, $bin_op_non_commut, $operant2_non_commut) $(if $if_expr_non_commut)? => $block_to_execute_non_commut
17                )+)?
18            }
19        }
20    };
21}