From a358e79a85b0677fc5a51de980add87c4f28cf41 Mon Sep 17 00:00:00 2001 From: Andrew Poelstra Date: Tue, 18 Feb 2025 15:55:14 +0000 Subject: [PATCH] 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. --- units/src/amount/result.rs | 2 -- units/src/internal_macros.rs | 6 +++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/units/src/amount/result.rs b/units/src/amount/result.rs index a8582a5e1..4d052ff6b 100644 --- a/units/src/amount/result.rs +++ b/units/src/amount/result.rs @@ -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() } } -} -crate::internal_macros::impl_op_for_references! { impl ops::Add> for Amount { type Output = NumOpResult; diff --git a/units/src/internal_macros.rs b/units/src/internal_macros.rs index d65167518..d5d0f14d1 100644 --- a/units/src/internal_macros.rs +++ b/units/src/internal_macros.rs @@ -18,14 +18,14 @@ /// You must specify `$other_ty` and you may not use `Self`. So e.g. you need /// to write `impl ops::Add for Amount { ... }` when calling this macro. macro_rules! impl_op_for_references { - ( + ($( impl $($op_trait:ident)::+<$other_ty:ty> for $ty:ty { type Output = $($main_output:ty)*; fn $op:ident($($main_args:tt)*) -> Self::Output { $($main_impl:tt)* } } - ) => { + )+) => {$( impl $($op_trait)::+<$other_ty> for $ty { type Output = $($main_output)*; fn $op($($main_args)*) -> Self::Output { @@ -53,7 +53,7 @@ macro_rules! impl_op_for_references { (*self).$op(*rhs) } } - }; + )+}; } pub(crate) use impl_op_for_references;