macro_rules! commutative_binop {
(
$( [ $($generic:tt)* ] )?
impl Add for $lhs:ty, $rhs:ty
$( where $($bound:tt)* )?
) => { ... };
(
$( [ $($generic:tt)* ] )?
impl Mul for $lhs:ty, $rhs:ty
$( where $($bound:tt)* )?
) => { ... };
(
$( [ $($generic:tt)* ] )?
impl $impl:ident, $meth:ident for $lhs:ty, $rhs:ty
$( where $($bound:tt)* )?
) => { ... };
}
Expand description
For types T
, U
for which binary operator binop
is implemented (T binop U
), also implement U binop T
.
This macro will fail if LHS
= RHS
.
For readability, the expected syntax of the macro is the following:
( [ Generics ] )?
impl Trait, Method for LHS(, RHS)?
( where Bounds )?
Generics
are comma-seperated type or const genericsTrait
is the trait to be implementedMethod
is the method thatTrait
defines
(can be ommitted forAdd
andMul
)LHS
is the type of the left hand side of the original operation (i.e.T
)RHS
is the type of the right hand side of the original operation (i.e.U
)Bounds
are comma-seperated trait bounds for the listed generics
Note in particular that LHS
and RHS
denote the left and right side of the original operation, not the one being created. The reason for this is to be consistent with all other macros in this crate, even if it seems unintuitive.