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:
Andrew Poelstra 2025-02-18 15:55:14 +00:00
parent 2da332e04a
commit a358e79a85
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
2 changed files with 3 additions and 5 deletions

View File

@ -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>;

View File

@ -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;