From e917f5d1ab357e501d4472f095b966cdf4cd83b4 Mon Sep 17 00:00:00 2001 From: Nadir Fejzic Date: Sun, 19 Nov 2023 16:26:29 +0100 Subject: [PATCH] fix: generalize `from_types` macro --- src/elements/mn.rs | 3 ++- src/lib.rs | 13 ++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/elements/mn.rs b/src/elements/mn.rs index e90f0fa..fd26182 100644 --- a/src/elements/mn.rs +++ b/src/elements/mn.rs @@ -18,7 +18,8 @@ impl<'a> From<&'a str> for Num { } } -crate::from_types!(u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize); +crate::from_types!(u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize => Num; + |val| Num { num: format!("{}", val), attributes: Default::default() }); impl From for MathMl where diff --git a/src/lib.rs b/src/lib.rs index d38d64c..b26f13b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,6 +4,8 @@ pub mod attributes; pub mod elements; pub mod markers; +use elements::Num; + #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] pub(crate) enum Tag { Num(Num), @@ -16,19 +18,16 @@ pub struct MathMl { } macro_rules! from_types { - ($($type:ty),* $(,)?) => { + ($($type:path),* $(,)? => $for_type:path; $func:expr) => { $( - impl From<$type> for Num { + impl From<$type> for $for_type { fn from(value: $type) -> Self { - Self { - num: format!("{}", value), - attributes: Vec::default(), - } + let from_value = $func; + from_value(value) } } )* }; } -use elements::Num; pub(crate) use from_types;