diff --git a/units/src/result.rs b/units/src/result.rs index afe268875..0663a6231 100644 --- a/units/src/result.rs +++ b/units/src/result.rs @@ -110,25 +110,22 @@ pub(crate) trait OptionExt { fn valid_or_error(self) -> NumOpResult; } -impl OptionExt for Option { - #[inline] - fn valid_or_error(self) -> NumOpResult { - match self { - Some(amount) => R::Valid(amount), - None => R::Error(NumOpError {}), - } - } -} - -impl OptionExt for Option { - #[inline] - fn valid_or_error(self) -> NumOpResult { - match self { - Some(amount) => R::Valid(amount), - None => R::Error(NumOpError {}), - } +macro_rules! impl_opt_ext { + ($($ty:ident),* $(,)?) => { + $( + impl OptionExt<$ty> for Option<$ty> { + #[inline] + fn valid_or_error(self) -> NumOpResult<$ty> { + match self { + Some(amount) => R::Valid(amount), + None => R::Error(NumOpError {}), + } + } + } + )* } } +impl_opt_ext!(Amount, SignedAmount); /// An error occurred while doing a mathematical operation. #[derive(Debug, Copy, Clone, PartialEq, Eq)]