units: allow multiple invocations in impl_op_for_references macro
This is not too complicated a change to support and it will reduce the noise in the following commits a fair bit.
This commit is contained in:
parent
2da332e04a
commit
a358e79a85
|
@ -129,9 +129,7 @@ crate::internal_macros::impl_op_for_references! {
|
||||||
|
|
||||||
fn add(self, rhs: Amount) -> Self::Output { self.checked_add(rhs).valid_or_error() }
|
fn add(self, rhs: Amount) -> Self::Output { self.checked_add(rhs).valid_or_error() }
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
crate::internal_macros::impl_op_for_references! {
|
|
||||||
impl ops::Add<NumOpResult<Amount>> for Amount {
|
impl ops::Add<NumOpResult<Amount>> for Amount {
|
||||||
type Output = NumOpResult<Amount>;
|
type Output = NumOpResult<Amount>;
|
||||||
|
|
||||||
|
|
|
@ -18,14 +18,14 @@
|
||||||
/// You must specify `$other_ty` and you may not use `Self`. So e.g. you need
|
/// You must specify `$other_ty` and you may not use `Self`. So e.g. you need
|
||||||
/// to write `impl ops::Add<Amount> for Amount { ... }` when calling this macro.
|
/// to write `impl ops::Add<Amount> for Amount { ... }` when calling this macro.
|
||||||
macro_rules! impl_op_for_references {
|
macro_rules! impl_op_for_references {
|
||||||
(
|
($(
|
||||||
impl $($op_trait:ident)::+<$other_ty:ty> for $ty:ty {
|
impl $($op_trait:ident)::+<$other_ty:ty> for $ty:ty {
|
||||||
type Output = $($main_output:ty)*;
|
type Output = $($main_output:ty)*;
|
||||||
fn $op:ident($($main_args:tt)*) -> Self::Output {
|
fn $op:ident($($main_args:tt)*) -> Self::Output {
|
||||||
$($main_impl:tt)*
|
$($main_impl:tt)*
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
) => {
|
)+) => {$(
|
||||||
impl $($op_trait)::+<$other_ty> for $ty {
|
impl $($op_trait)::+<$other_ty> for $ty {
|
||||||
type Output = $($main_output)*;
|
type Output = $($main_output)*;
|
||||||
fn $op($($main_args)*) -> Self::Output {
|
fn $op($($main_args)*) -> Self::Output {
|
||||||
|
@ -53,7 +53,7 @@ macro_rules! impl_op_for_references {
|
||||||
(*self).$op(*rhs)
|
(*self).$op(*rhs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
)+};
|
||||||
}
|
}
|
||||||
pub(crate) use impl_op_for_references;
|
pub(crate) use impl_op_for_references;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue