summaryrefslogtreecommitdiff
path: root/library/src/text
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-03-13 21:39:38 +0100
committerLaurenz <laurmaedje@gmail.com>2023-03-13 21:40:06 +0100
commit880b1847bd4170ce80be5781c2163ba085cdcaff (patch)
tree3fbfdb70cb04c4922f0ec9e3f29f2c63d11d753b /library/src/text
parentcb3c263c4a67f4d361dbdb5048a1c073bd1fff96 (diff)
Derive `Cast` for enums
Diffstat (limited to 'library/src/text')
-rw-r--r--library/src/text/misc.rs15
-rw-r--r--library/src/text/mod.rs44
2 files changed, 8 insertions, 51 deletions
diff --git a/library/src/text/misc.rs b/library/src/text/misc.rs
index 029e15f4..5a5c8514 100644
--- a/library/src/text/misc.rs
+++ b/library/src/text/misc.rs
@@ -246,7 +246,7 @@ cast_from_value! {
}
/// A case transformation on text.
-#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
+#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Cast)]
pub enum Case {
/// Everything is lowercased.
Lower,
@@ -264,19 +264,6 @@ impl Case {
}
}
-cast_from_value! {
- Case,
- "lower" => Self::Lower,
- "upper" => Self::Upper,
-}
-
-cast_to_value! {
- v: Case => Value::from(match v {
- Case::Lower => "lower",
- Case::Upper => "upper",
- })
-}
-
/// Display text in small capitals.
///
/// _Note:_ This enables the OpenType `smcp` feature for the font. Not all fonts
diff --git a/library/src/text/mod.rs b/library/src/text/mod.rs
index a81ef3d7..845ffe29 100644
--- a/library/src/text/mod.rs
+++ b/library/src/text/mod.rs
@@ -686,53 +686,23 @@ cast_to_value! {
}
/// Which kind of numbers / figures to select.
-#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
+#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Cast)]
pub enum NumberType {
- /// Numbers that fit well with capital text. ("lnum")
- Lining,
- /// Numbers that fit well into a flow of upper- and lowercase text. ("onum")
- OldStyle,
-}
-
-cast_from_value! {
- NumberType,
/// Numbers that fit well with capital text (the OpenType `lnum`
/// font feature).
- "lining" => Self::Lining,
- // Numbers that fit well into a flow of upper- and lowercase text (the
+ Lining,
+ /// Numbers that fit well into a flow of upper- and lowercase text (the
/// OpenType `onum` font feature).
- "old-style" => Self::OldStyle,
-}
-
-cast_to_value! {
- v: NumberType => Value::from(match v {
- NumberType::Lining => "lining",
- NumberType::OldStyle => "old-style",
- })
+ OldStyle,
}
/// The width of numbers / figures.
-#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
+#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Cast)]
pub enum NumberWidth {
- /// Number widths are glyph specific. ("pnum")
- Proportional,
- /// All numbers are of equal width / monospaced. ("tnum")
- Tabular,
-}
-
-cast_from_value! {
- NumberWidth,
/// Numbers with glyph-specific widths (the OpenType `pnum` font feature).
- "proportional" => Self::Proportional,
+ Proportional,
/// Numbers of equal width (the OpenType `tnum` font feature).
- "tabular" => Self::Tabular,
-}
-
-cast_to_value! {
- v: NumberWidth => Value::from(match v {
- NumberWidth::Proportional => "proportional",
- NumberWidth::Tabular => "tabular",
- })
+ Tabular,
}
/// OpenType font features settings.