mathml_core/numbers/
constructors.rs1use super::*;
2
3impl MathError {
4 pub fn new<S>(message: S) -> Self
6 where
7 S: ToString,
8 {
9 Self { message: message.to_string() }
10 }
11}
12
13impl MathNumber {
14 pub fn new<S>(text: S) -> Self
16 where
17 S: ToString,
18 {
19 Self { number: text.to_string() }
20 }
21}
22
23macro_rules! make_number {
24 ($($t:ty),*) => {
25 $(
26 impl From<$t> for MathNumber {
27 fn from(value: $t) -> Self {
28 Self::new(value)
29 }
30 }
31 )*
32 };
33}
34
35make_number!(i8, i16, i32, i64, i128, isize);
36make_number!(u8, u16, u32, u64, u128, usize);
37make_number!(f32, f64);
38
39impl MathElement for MathFraction {
40 fn tag_name(&self) -> &'static str {
41 "mfrac"
42 }
43
44 fn get_attributes(&self) -> &BTreeMap<String, String> {
45 todo!()
46 }
47
48 fn mut_attributes(&mut self) -> &mut BTreeMap<String, String> {
49 todo!()
50 }
51}
52
53impl MathFraction {
54 pub fn new<N, D>(numerator: N, denominator: D) -> Self
56 where
57 N: Into<MathML>,
58 D: Into<MathML>,
59 {
60 Self { numerator: numerator.into(), denominator: denominator.into(), line_thickness: Default::default() }
61 }
62 pub fn with_thickness<T>(mut self, line_thickness: T) -> Self
64 where
65 T: Into<LineThickness>,
66 {
67 self.line_thickness = line_thickness.into();
68 self
69 }
70}
71
72impl Default for LineThickness {
73 fn default() -> Self {
74 LineThickness::Medium
75 }
76}
77
78impl MathML {
79 pub fn number<N>(n: N) -> Self
81 where
82 N: Into<MathNumber>,
83 {
84 n.into().into()
85 }
86 pub fn fraction<N, D>(numerator: N, denominator: D) -> Self
88 where
89 N: Into<MathML>,
90 D: Into<MathML>,
91 {
92 MathFraction::new(numerator, denominator).into()
93 }
94 pub fn error<S>(message: S) -> Self
96 where
97 S: ToString,
98 {
99 MathError::new(message).into()
100 }
101}