#[macro_export]
macro_rules! commutative_binop {
($type:ident, $trait:ident, $trait_fn:ident, $inplace:ident, $inplace_fn:ident) => {
impl $inplace<$type> for $type {
#[inline(always)] fn $inplace_fn(&mut self, rhs: Self) {
self.$inplace_fn(&rhs)
}
}
impl $trait<$type> for $type {
type Output = Self;
#[inline(always)] fn $trait_fn(self, rhs: Self) -> Self {
self.$trait_fn(&rhs)
}
}
impl $trait<&$type> for $type {
type Output = Self;
#[inline(always)] fn $trait_fn(mut self, rhs: &Self) -> Self {
self.$inplace_fn(rhs);
self
}
}
impl $trait<$type> for &$type {
type Output = $type;
#[inline(always)] fn $trait_fn(self, rhs: $type) -> $type {
rhs.$trait_fn(self)
}
}
impl $trait<&$type> for &$type {
type Output = $type;
#[inline(always)] 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 {
#[inline(always)] fn $inplace_fn(&mut self, rhs: Self) {
self.$inplace_fn(&rhs)
}
}
impl $trait<$type> for $type {
type Output = Self;
#[inline(always)] fn $trait_fn(self, rhs: Self) -> Self {
self.$trait_fn(&rhs)
}
}
impl $trait<&$type> for $type {
type Output = Self;
#[inline(always)] fn $trait_fn(mut self, rhs: &Self) -> Self {
self.$inplace_fn(rhs);
self
}
}
impl $trait<$type> for &$type {
type Output = $type;
#[inline(always)] fn $trait_fn(self, rhs: $type) -> $type {
self.clone().$trait_fn(rhs)
}
}
impl $trait<&$type> for &$type {
type Output = $type;
#[inline(always)] fn $trait_fn(self, rhs: &$type) -> $type {
self.clone().$trait_fn(rhs)
}
}
};
}
#[macro_export]
macro_rules! assign_ops_from_trait {
(
$type:ident,
$rhs:ident,
$op_trait:ident,
$op_fn:ident,
$trait:ident,
$trait_assign_fn:ident
) => {
impl $op_trait<$rhs> for $type {
#[inline(always)] fn $op_fn(&mut self, rhs: $rhs) {
<$type as $trait<&$rhs>>::$trait_assign_fn(self, &rhs)
}
}
impl $op_trait<&$rhs> for $type {
#[inline(always)] fn $op_fn(&mut self, rhs: &$rhs) {
<$type as $trait<&$rhs>>::$trait_assign_fn(self, rhs)
}
}
};
}
#[macro_export]
macro_rules! self_ops_from_trait {
(
$type:ident,
$op_trait:ident,
$op_fn:ident,
$trait:ident,
$trait_fn:ident,
$trait_assign_fn:ident
) => {
impl $op_trait<&$type> for &$type {
type Output = $type;
#[inline(always)] fn $op_fn(self, rhs: &$type) -> $type {
<$type as $trait<&$type>>::$trait_fn(self, rhs)
}
}
impl $op_trait<&$type> for $type {
type Output = $type;
#[inline(always)] fn $op_fn(mut self, rhs: &$type) -> $type {
<$type as $trait<&$type>>::$trait_assign_fn(&mut self, rhs);
self
}
}
impl $op_trait<$type> for &$type {
type Output = $type;
#[inline(always)] fn $op_fn(self, mut rhs: $type) -> $type {
<$type as $trait<&$type>>::$trait_assign_fn(&mut rhs, self);
rhs
}
}
impl $op_trait<$type> for $type {
type Output = $type;
#[inline(always)] fn $op_fn(mut self, rhs: $type) -> $type {
<$type as $trait<&$type>>::$trait_assign_fn(&mut self, &rhs);
self
}
}
};
}
#[macro_export]
macro_rules! noncommutative_self_ops_from_trait {
(
$type:ident,
$op_trait:ident,
$op_fn:ident,
$trait:ident,
$trait_fn:ident,
$trait_assign_fn:ident
) => {
impl $op_trait<&$type> for &$type {
type Output = $type;
#[inline(always)] fn $op_fn(self, rhs: &$type) -> $type {
<$type as $trait<&$type>>::$trait_fn(self, rhs)
}
}
impl $op_trait<&$type> for $type {
type Output = $type;
#[inline(always)] fn $op_fn(mut self, rhs: &$type) -> $type {
<$type as $trait<&$type>>::$trait_assign_fn(&mut self, rhs);
self
}
}
impl $op_trait<$type> for &$type {
type Output = $type;
#[inline(always)] fn $op_fn(self, rhs: $type) -> $type {
<$type as $trait<&$type>>::$trait_fn(self, &rhs)
}
}
impl $op_trait<$type> for $type {
type Output = $type;
#[inline(always)] fn $op_fn(mut self, rhs: $type) -> $type {
<$type as $trait<&$type>>::$trait_assign_fn(&mut self, &rhs);
self
}
}
};
}