#[macro_export]
macro_rules! commutative_binop {
($type:ident, $trait:ident, $trait_fn:ident, $inplace:ident, $inplace_fn:ident) => {
impl $inplace<$type> for $type {
fn $inplace_fn(&mut self, rhs: Self) {
self.$inplace_fn(&rhs)
}
}
impl $trait<$type> for $type {
type Output = Self;
fn $trait_fn(self, rhs: Self) -> Self {
self.$trait_fn(&rhs)
}
}
impl $trait<&$type> for $type {
type Output = Self;
fn $trait_fn(mut self, rhs: &Self) -> Self {
self.$inplace_fn(rhs);
self
}
}
impl $trait<$type> for &$type {
type Output = $type;
fn $trait_fn(self, rhs: $type) -> $type {
rhs.$trait_fn(self)
}
}
impl $trait<&$type> for &$type {
type Output = $type;
fn $trait_fn(self, rhs: &$type) -> $type {
self.clone().$trait_fn(rhs)
}
}
};
}
#[macro_export]
macro_rules! noncommutative_binop {
($type:ident, $trait:ident, $trait_fn:ident, $inplace:ident, $inplace_fn:ident) => {
impl $inplace<$type> for $type {
fn $inplace_fn(&mut self, rhs: Self) {
self.$inplace_fn(&rhs)
}
}
impl $trait<$type> for $type {
type Output = Self;
fn $trait_fn(self, rhs: Self) -> Self {
self.$trait_fn(&rhs)
}
}
impl $trait<&$type> for $type {
type Output = Self;
fn $trait_fn(mut self, rhs: &Self) -> Self {
self.$inplace_fn(rhs);
self
}
}
impl $trait<$type> for &$type {
type Output = $type;
fn $trait_fn(self, rhs: $type) -> $type {
self.clone().$trait_fn(rhs)
}
}
impl $trait<&$type> for &$type {
type Output = $type;
fn $trait_fn(self, rhs: &$type) -> $type {
self.clone().$trait_fn(rhs)
}
}
};
}