Skip to content

Commit 6038ac3

Browse files
committed
Address comments
1 parent 24687ad commit 6038ac3

File tree

1 file changed

+28
-50
lines changed

1 file changed

+28
-50
lines changed

src/styling.rs

Lines changed: 28 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -60,54 +60,6 @@ pub enum MathStyle {
6060
Stretched,
6161
}
6262

63-
impl MathStyle {
64-
/// Applies the style to a given `char`.
65-
///
66-
/// Note that some styles will convert a character into multiple
67-
/// characters, hence this function always returns an array of two
68-
/// characters.
69-
///
70-
/// # Examples
71-
///
72-
/// ```
73-
/// use codex::styling::MathStyle;
74-
///
75-
/// assert_eq!(['𝑴', '\0'], MathStyle::SerifItalicBold.apply('M'));
76-
/// assert_eq!(['𞸪', '\0'], MathStyle::Initial.apply('ك'));
77-
/// assert_eq!(['ⅈ', '\0'], MathStyle::DoubleStruckItalic.apply('i'));
78-
/// assert_eq!(['𝓴', '\u{fe01}'], MathStyle::RoundhandBold.apply('k'));
79-
/// ```
80-
pub fn apply(self, c: char) -> [char; 2] {
81-
use mappings::*;
82-
use MathStyle::*;
83-
match self {
84-
Serif => [to_serif(c), '\0'],
85-
SerifBold => [to_serif_bold(c), '\0'],
86-
SerifItalic => [to_serif_italic(c), '\0'],
87-
SerifItalicBold => [to_serif_italic_bold(c), '\0'],
88-
SansSerif => [to_sans_serif(c), '\0'],
89-
SansSerifBold => [to_sans_serif_bold(c), '\0'],
90-
SansSerifItalic => [to_sans_serif_italic(c), '\0'],
91-
SansSerifItalicBold => [to_sans_serif_italic_bold(c), '\0'],
92-
Fraktur => [to_fraktur(c), '\0'],
93-
FrakturBold => [to_fraktur_bold(c), '\0'],
94-
Script => [to_script(c), '\0'],
95-
ScriptBold => [to_script_bold(c), '\0'],
96-
Chancery => to_chancery(c),
97-
ChanceryBold => to_chancery_bold(c),
98-
Roundhand => to_roundhand(c),
99-
RoundhandBold => to_roundhand_bold(c),
100-
DoubleStruck => [to_double_struck(c), '\0'],
101-
DoubleStruckItalic => [to_double_struck_italic(c), '\0'],
102-
Monospace => [to_monospace(c), '\0'],
103-
Initial => [to_initial(c), '\0'],
104-
Tailed => [to_tailed(c), '\0'],
105-
Looped => [to_looped(c), '\0'],
106-
Stretched => [to_stretched(c), '\0'],
107-
}
108-
}
109-
}
110-
11163
/// Returns an iterator that yields the styled equivalent of a `char`.
11264
///
11365
/// This `struct` is created by the [`to_style`] function. See its
@@ -201,9 +153,35 @@ impl fmt::Display for ToStyle {
201153
/// .collect::<String>();
202154
/// assert_eq!("𝕩ℽΩ𝔸𞺸𞺧𝟙⅀𞺮", s);
203155
/// ```
204-
#[inline]
205156
pub fn to_style(c: char, style: MathStyle) -> ToStyle {
206-
ToStyle::new(style.apply(c))
157+
use mappings::*;
158+
use MathStyle::*;
159+
let styled = match style {
160+
Serif => [to_serif(c), '\0'],
161+
SerifBold => [to_serif_bold(c), '\0'],
162+
SerifItalic => [to_serif_italic(c), '\0'],
163+
SerifItalicBold => [to_serif_italic_bold(c), '\0'],
164+
SansSerif => [to_sans_serif(c), '\0'],
165+
SansSerifBold => [to_sans_serif_bold(c), '\0'],
166+
SansSerifItalic => [to_sans_serif_italic(c), '\0'],
167+
SansSerifItalicBold => [to_sans_serif_italic_bold(c), '\0'],
168+
Fraktur => [to_fraktur(c), '\0'],
169+
FrakturBold => [to_fraktur_bold(c), '\0'],
170+
Script => [to_script(c), '\0'],
171+
ScriptBold => [to_script_bold(c), '\0'],
172+
Chancery => to_chancery(c),
173+
ChanceryBold => to_chancery_bold(c),
174+
Roundhand => to_roundhand(c),
175+
RoundhandBold => to_roundhand_bold(c),
176+
DoubleStruck => [to_double_struck(c), '\0'],
177+
DoubleStruckItalic => [to_double_struck_italic(c), '\0'],
178+
Monospace => [to_monospace(c), '\0'],
179+
Initial => [to_initial(c), '\0'],
180+
Tailed => [to_tailed(c), '\0'],
181+
Looped => [to_looped(c), '\0'],
182+
Stretched => [to_stretched(c), '\0'],
183+
};
184+
ToStyle::new(styled)
207185
}
208186

209187
/// Functions which map a `char` to its specified styled form.

0 commit comments

Comments
 (0)