mathml_core/identifiers/
constructors.rs

1use super::*;
2
3impl MathIdentifier {
4    /// Creates a new [`MathIdentifier`] with the given [`FontVariant`].
5    pub fn new<S>(text: S, variant: FontVariant) -> Self
6    where
7        S: ToString,
8    {
9        Self { identifier: text.to_string(), variant }
10    }
11    /// Creates a new [`MathIdentifier`] with the [`FontVariant::Normal`] variant.
12    pub fn normal<S>(text: S) -> Self
13    where
14        S: ToString,
15    {
16        Self { identifier: text.to_string(), variant: FontVariant::Normal }
17    }
18    /// Creates a new [`MathIdentifier`] with the [`FontVariant::Italic`] variant.
19    pub fn italic<S>(text: S) -> Self
20    where
21        S: ToString,
22    {
23        Self { identifier: text.to_string(), variant: FontVariant::Italic }
24    }
25    /// Gets the font variant of the identifier.
26    pub fn get_variant(&self) -> FontVariant {
27        self.variant
28    }
29    /// Gets the identifier of the identifier.
30    pub fn get_identifier(&self) -> &str {
31        &self.identifier
32    }
33}
34
35impl MathText {
36    /// Creates a new [`MathText`] with the given [`FontVariant`].
37    pub fn text<S>(text: S) -> Self
38    where
39        S: ToString,
40    {
41        Self { text: text.to_string(), is_string: false }
42    }
43    /// Creates a new [`MathText`] with the [`FontVariant::Normal`] variant.
44    pub fn string<S>(text: S) -> Self
45    where
46        S: ToString,
47    {
48        Self { text: text.to_string(), is_string: true }
49    }
50}
51
52impl MathML {
53    /// Creates a new [`MathIdentifier`] with the [`FontVariant::Italic`] variant.
54    pub fn identifier<S>(text: S) -> Self
55    where
56        S: ToString,
57    {
58        MathIdentifier::italic(text).into()
59    }
60    /// Creates a new [`MathText`] with the [`FontVariant::Normal`] variant.
61    pub fn text<S>(text: S) -> Self
62    where
63        S: ToString,
64    {
65        MathText::text(text).into()
66    }
67    /// Creates a new [`MathText`] with the [`FontVariant::Normal`] variant.
68    pub fn string<S>(text: S) -> Self
69    where
70        S: ToString,
71    {
72        MathText::string(text).into()
73    }
74}