macro_rules! implement_for_others {
($bridge_type:ident, $type:ident, $output_type:ident, Mul Scalar for $($source_type:ident)*) => {
$(#[doc(hidden)] impl Mul<$source_type> for &$type {
type Output = $output_type;
paste::paste! {
#[doc = "Documentation can be found at [`" $type "::mul`]."]
fn mul(self, scalar: $source_type) -> Self::Output {
self.mul($bridge_type::from(scalar))
}
}
}
#[doc(hidden)]
impl Mul<$source_type> for $type {
type Output = $output_type;
paste::paste! {
#[doc = "Documentation can be found at [`" $type "::mul`]."]
fn mul(self, scalar: $source_type) -> Self::Output {
self.mul($bridge_type::from(scalar))
}
}
}
#[doc(hidden)]
impl Mul<&$type> for $source_type {
type Output = $output_type;
paste::paste! {
#[doc = "Documentation can be found at [`" $type "::mul`]."]
fn mul(self, matrix: &$type) -> Self::Output {
matrix.mul($bridge_type::from(self))
}
}
}
#[doc(hidden)]
impl Mul<$type> for $source_type {
type Output = $output_type;
paste::paste! {
#[doc = "Documentation can be found at [`" $type "::mul`]."]
fn mul(self, matrix: $type) -> Self::Output {
matrix.mul($bridge_type::from(self))
}
}
})*
};
($bridge_type:ident, $type:ident, $output_type:ident, Div Scalar for $($source_type:ident)*) => {
$(#[doc(hidden)] impl Div<$source_type> for &$type {
type Output = $output_type;
paste::paste! {
#[doc = "Documentation can be found at [`" $type "::div`]."]
fn div(self, scalar: $source_type) -> Self::Output {
self.div($bridge_type::from(scalar))
}
}
}
#[doc(hidden)]
impl Div<$source_type> for $type {
type Output = $output_type;
paste::paste! {
#[doc = "Documentation can be found at [`" $type "::div`]."]
fn div(self, scalar: $source_type) -> Self::Output {
self.div($bridge_type::from(scalar))
}
}
})*
};
($bridge_type:ident, $type:ident, Rem for $($source_type:ident)*) => {
$(#[doc(hidden)] impl Rem<$source_type> for &$type {
type Output = $type;
paste::paste! {
#[doc = "Documentation can be found at [`" $type "::rem`]."]
fn rem(self, modulus: $source_type) -> Self::Output {
self.rem($bridge_type::from(modulus))
}
}
}
impl Rem<$source_type> for $type {
type Output = $type;
paste::paste! {
#[doc = "Documentation can be found at [`" $type "::rem`]."]
fn rem(self, modulus: $source_type) -> Self::Output {
self.rem($bridge_type::from(modulus))
}
}
})*
};
($bridge_type:ident, $type:ident, PartialEq for $($source_type:ident)*) => {
$(#[doc(hidden)] impl PartialEq<$source_type> for $type {
paste::paste! {
#[doc = "Documentation can be found at [`" $type "::partialEq`]."]
fn eq(&self, other: &$source_type) -> bool {
self.eq(&$bridge_type::from(other))
}
}
}
#[doc(hidden)] impl PartialEq<$type> for $source_type {
paste::paste! {
#[doc = "Documentation can be found at [`" $type "::partialEq`]."]
fn eq(&self, other: &$type) -> bool {
other.eq(&$bridge_type::from(self))
}
}
})*
};
($bridge_type:ident, $type:ident, PartialOrd for $($source_type:ident)*) => {
$(#[doc(hidden)] impl PartialOrd<$source_type> for $type {
paste::paste! {
#[doc = "Documentation can be found at [`" $type "::partialEq`]."]
fn partial_cmp(&self, other: &$source_type) -> Option<Ordering> {
self.partial_cmp(&$bridge_type::from(other))
}
}
}
#[doc(hidden)] impl PartialOrd<$type> for $source_type {
paste::paste! {
#[doc = "Documentation can be found at [`" $type "::partialEq`]."]
fn partial_cmp(&self, other: &$type) -> Option<Ordering> {
$bridge_type::from(self).partial_cmp(other)
}
}
})*
};
}
pub(crate) use implement_for_others;
macro_rules! implement_for_owned {
($source_type:ident, $output_type:ident, $type:ident, Evaluate) => {
impl Evaluate<$source_type, $output_type> for $type {
paste::paste! {
#[doc = "Documentation can be found at [`" $type "::evaluate`] for &[`" $source_type "`]."]
fn evaluate(
&self,
value: $source_type
) -> $output_type {
self.evaluate(&value)
}
}
}
};
($source_type:ident, $type:ident, From) => {
impl From<$source_type> for $type {
paste::paste! {
#[doc = "Documentation can be found at [`" $type "::from`] for &[`" $source_type "`]."]
fn from(
value: $source_type
) -> Self {
Self::from(&value)
}
}
}
};
($source_type:ident, $type:ident, SetCoefficient) => {
impl SetCoefficient<$source_type> for $type {
paste::paste! {
#[doc = "Documentation can be found at [`" $type "::set_coeff`] for &[`" $source_type "`]."]
unsafe fn set_coeff_unchecked(
&mut self,
index: i64,
value: $source_type,
) {
unsafe { self.set_coeff_unchecked(index, &value) }
}
}
}
};
($source_type:ident, $type:ident, MatrixSetEntry) => {
impl MatrixSetEntry<$source_type> for $type {
paste::paste! {
#[doc = "Documentation can be found at [`" $type "::set_entry`] for &[`" $source_type "`]."]
fn set_entry(
&mut self,
row: impl TryInto<i64> + Display,
column: impl TryInto<i64> + Display,
value: $source_type,
) -> Result<(), MathError> {
self.set_entry(row, column, &value)
}
#[doc = "Documentation can be found at [`" $type "::set_entry`] for &[`" $source_type "`]."]
unsafe fn set_entry_unchecked(
&mut self,
row: i64,
column: i64,
value: $source_type,
) {
unsafe { self.set_entry_unchecked(row, column, &value) };
}
}
}
};
}
pub(crate) use implement_for_owned;
macro_rules! implement_empty_trait_owned_ref {
($trait_name:ident for $($type:ty)*) => {
$(
impl $trait_name for $type {}
impl $trait_name for &$type {}
)*
};
}
pub(crate) use implement_empty_trait_owned_ref;
macro_rules! implement_trait_reverse {
($trait:ident, $trait_function:ident, $type:ident, $other_type:ident, $output_type:ident) => {
#[doc(hidden)]
impl $trait<$other_type> for $type {
paste::paste! {
fn $trait_function(&self, other: &$other_type) -> $output_type {
other.$trait_function(self)
}
}
}
};
}
pub(crate) use implement_trait_reverse;