macro_rules! impl_borrow_variants {
($target:ty, $trait:ident, $fn_name:ident, $op:tt, $($gen:ident: $gen_ty:ident),*) => {
impl<$($gen:$gen_ty),*> $trait for $target {
type Output = $target;
fn $fn_name(self) -> Self::Output {
$op &self
}
}
};
($lhs:ty, $trait:ident, $fn_name:ident, $op:tt, $rhs:ty, $($gen:ident: $gen_ty:ident),*) => {
impl_borrow_variants!($lhs, $trait, $fn_name, $op, $rhs, Output=$lhs, $($gen: $gen_ty),*);
};
($lhs:ty, $trait:ident, $fn_name:ident, $op:tt, $rhs:ty, Output=$out_type:ty, $($gen:ident: $gen_ty:ident),*) => {
impl<'a, $($gen: $gen_ty),*> $trait<$rhs> for &'a $lhs {
type Output = $out_type;
fn $fn_name(self, rhs: $rhs) -> Self::Output {
self $op &rhs
}
}
impl<'a, $($gen: $gen_ty),*> $trait<&'a $rhs> for $lhs {
type Output = $out_type;
fn $fn_name(self, rhs: &'a $rhs) -> Self::Output {
&self $op rhs
}
}
impl<$($gen: $gen_ty),*> $trait<$rhs> for $lhs {
type Output = $out_type;
fn $fn_name(self, rhs: $rhs) -> Self::Output {
&self $op &rhs
}
}
}
}
macro_rules! impl_commutative {
($lhs:ty, $trait:ident, $fn_name:ident, $op:tt, $rhs:ty, $($gen:ident: $gen_ty:ident),*) => {
impl_commutative!($lhs, $trait, $fn_name, $op, $rhs, Output=$lhs, $($gen: $gen_ty),*);
};
($lhs:ty, $trait:ident, $fn_name:ident, $op:tt, $rhs:ty, Output=$out_type:ty, $($gen:ident: $gen_ty:ident),*) => {
impl<'a, $($gen: $gen_ty),*> $trait<&'a $lhs> for &'a $rhs {
type Output = $out_type;
fn $fn_name(self, rhs: &'a $lhs) -> Self::Output {
rhs $op self
}
}
impl<'a, $($gen: $gen_ty),*> $trait<$lhs> for &'a $rhs
{
type Output = $out_type;
fn $fn_name(self, rhs: $lhs) -> Self::Output {
&rhs $op self
}
}
impl<'a, $($gen: $gen_ty),*> $trait<&'a $lhs> for $rhs
{
type Output = $out_type;
fn $fn_name(self, rhs: &'a $lhs) -> Self::Output {
rhs $op &self
}
}
impl<$($gen: $gen_ty),*> $trait<$lhs> for $rhs
{
type Output = $out_type;
fn $fn_name(self, rhs: $lhs) -> Self::Output {
&rhs $op &self
}
}
};
}
pub(crate) use impl_borrow_variants;
pub(crate) use impl_commutative;