#![macro_use]
macro_rules! _binop_impl(
($Op: ident, $op: ident;
$lhs: ident: $Lhs: ty, $rhs: ident: $Rhs: ty, Output = $Output: ty;
$action: expr; $($lives: tt),*) => {
impl<$($lives ,)*> $Op<$Rhs> for $Lhs {
type Output = $Output;
#[inline]
fn $op($lhs, $rhs: $Rhs) -> Self::Output {
$action
}
}
}
);
macro_rules! binop_impl_all(
($Op: ident, $op: ident;
// This is types and variable names of each side of the operand, and then the type of the
// output.
$lhs: ident: $Lhs: ty, $rhs: ident: $Rhs: ty, Output = $Output: ty;
// These are the expressions used to perform each of the operations on the different
// combinations of value and reference. When implementing, by converting all values to the
// form ref * ref, there is only a single implementation required.
[ref ref] => $action_ref_ref: expr;) => {
_binop_impl!(
$Op, $op;
$lhs: $Lhs, $rhs: $Rhs, Output = $Output;
&$lhs * &$rhs; );
_binop_impl!(
$Op, $op;
$lhs: &'a $Lhs, $rhs: $Rhs, Output = $Output;
$lhs * &$rhs; 'a);
_binop_impl!(
$Op, $op;
$lhs: $Lhs, $rhs: &'b $Rhs, Output = $Output;
&$lhs * $rhs; 'b);
_binop_impl!(
$Op, $op;
$lhs: &'a $Lhs, $rhs: &'b $Rhs, Output = $Output;
$action_ref_ref; 'a, 'b);
}
);