#[macro_export]
macro_rules! impl_unit_from_conversions {
($unit:ty) => {};
($first:ty, $($rest:ty),+ $(,)?) => {
$(
impl From<$crate::Quantity<$first>> for $crate::Quantity<$rest> {
fn from(value: $crate::Quantity<$first>) -> Self {
value.to::<$rest>()
}
}
impl From<$crate::Quantity<$rest>> for $crate::Quantity<$first> {
fn from(value: $crate::Quantity<$rest>) -> Self {
value.to::<$first>()
}
}
)+
$crate::impl_unit_from_conversions!($($rest),+);
};
}
#[macro_export]
macro_rules! impl_unit_cross_unit_ops {
($unit:ty) => {};
($first:ty, $($rest:ty),+ $(,)?) => {
$(
impl<S: $crate::scalar::Real> PartialEq<$crate::Quantity<$rest, S>> for $crate::Quantity<$first, S> {
#[inline]
fn eq(&self, other: &$crate::Quantity<$rest, S>) -> bool {
self.value() == other.to::<$first>().value()
}
}
impl<S: $crate::scalar::Real> PartialEq<$crate::Quantity<$first, S>> for $crate::Quantity<$rest, S> {
#[inline]
fn eq(&self, other: &$crate::Quantity<$first, S>) -> bool {
self.value() == other.to::<$rest>().value()
}
}
impl<S: $crate::scalar::Real> PartialOrd<$crate::Quantity<$rest, S>> for $crate::Quantity<$first, S> {
#[inline]
fn partial_cmp(&self, other: &$crate::Quantity<$rest, S>) -> Option<core::cmp::Ordering> {
self.value().partial_cmp(&other.to::<$first>().value())
}
}
impl<S: $crate::scalar::Real> PartialOrd<$crate::Quantity<$first, S>> for $crate::Quantity<$rest, S> {
#[inline]
fn partial_cmp(&self, other: &$crate::Quantity<$first, S>) -> Option<core::cmp::Ordering> {
self.value().partial_cmp(&other.to::<$rest>().value())
}
}
)+
$crate::impl_unit_cross_unit_ops!($($rest),+);
};
}
#[macro_export]
macro_rules! impl_unit_conversions {
($($unit:ty),+ $(,)?) => {
$crate::impl_unit_from_conversions!($($unit),+);
$crate::impl_unit_cross_unit_ops!($($unit),+);
};
}