Skip to content

Commit

Permalink
fix: generalize from_types macro
Browse files Browse the repository at this point in the history
  • Loading branch information
nfejzic committed Nov 20, 2023
1 parent c0ce1b0 commit e917f5d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/elements/mn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> From<T> for MathMl
where
Expand Down
13 changes: 6 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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;

0 comments on commit e917f5d

Please sign in to comment.