1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
use super::*;

impl MathError {
    /// Creates a new [`MathError`] with the given message.
    pub fn new<S>(message: S) -> Self
    where
        S: ToString,
    {
        Self { message: message.to_string() }
    }
}

impl MathNumber {
    /// Creates a new [`MathNumber`] with the given value.
    pub fn new<S>(text: S) -> Self
    where
        S: ToString,
    {
        Self { number: text.to_string() }
    }
}

macro_rules! make_number {
    ($($t:ty),*) => {
        $(
            impl From<$t> for MathNumber {
                fn from(value: $t) -> Self {
                    Self::new(value)
                }
            }
        )*
    };
}

make_number!(i8, i16, i32, i64, i128, isize);
make_number!(u8, u16, u32, u64, u128, usize);
make_number!(f32, f64);

// noinspection SpellCheckingInspection
impl MathElement for MathFraction {
    fn tag_name(&self) -> &'static str {
        "mfrac"
    }

    fn get_attributes(&self) -> &BTreeMap<String, String> {
        todo!()
    }

    fn mut_attributes(&mut self) -> &mut BTreeMap<String, String> {
        todo!()
    }
}

impl MathFraction {
    /// Creates a new [`MathFraction`] with the given numerator and denominator.
    pub fn new<N, D>(numerator: N, denominator: D) -> Self
    where
        N: Into<MathML>,
        D: Into<MathML>,
    {
        Self { numerator: numerator.into(), denominator: denominator.into(), line_thickness: Default::default() }
    }
    /// Config the thickness of the line between the numerator and denominator, zero means no line.
    pub fn with_thickness<T>(mut self, line_thickness: T) -> Self
    where
        T: Into<LineThickness>,
    {
        self.line_thickness = line_thickness.into();
        self
    }
}

impl Default for LineThickness {
    fn default() -> Self {
        LineThickness::Medium
    }
}

impl MathML {
    /// Creates a new [`MathNumber`] with the given number.
    pub fn number<N>(n: N) -> Self
    where
        N: Into<MathNumber>,
    {
        n.into().into()
    }
    /// Creates a new [`MathFraction`] with the given numerator and denominator.
    pub fn fraction<N, D>(numerator: N, denominator: D) -> Self
    where
        N: Into<MathML>,
        D: Into<MathML>,
    {
        MathFraction::new(numerator, denominator).into()
    }
    /// Creates a new [`MathError`] with the given message.
    pub fn error<S>(message: S) -> Self
    where
        S: ToString,
    {
        MathError::new(message).into()
    }
}