1#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
3pub enum Weight {
4 #[default]
6 Regular,
7 Thin,
9 Light,
11 Bold,
13 Fill,
15 Duotone,
17}
18
19impl Weight {
20 pub const ALL: [Self; 6] = [
22 Self::Regular,
23 Self::Thin,
24 Self::Light,
25 Self::Bold,
26 Self::Fill,
27 Self::Duotone,
28 ];
29
30 #[must_use]
32 pub const fn as_str(self) -> &'static str {
33 match self {
34 Self::Regular => "regular",
35 Self::Thin => "thin",
36 Self::Light => "light",
37 Self::Bold => "bold",
38 Self::Fill => "fill",
39 Self::Duotone => "duotone",
40 }
41 }
42
43 #[must_use]
45 pub fn from_name(name: &str) -> Option<Self> {
46 Self::ALL.into_iter().find(|weight| weight.as_str() == name)
47 }
48
49 #[must_use]
51 pub const fn is_enabled(self) -> bool {
52 match self {
53 Self::Regular => cfg!(feature = "regular"),
54 Self::Thin => cfg!(feature = "thin"),
55 Self::Light => cfg!(feature = "light"),
56 Self::Bold => cfg!(feature = "bold"),
57 Self::Fill => cfg!(feature = "fill"),
58 Self::Duotone => cfg!(feature = "duotone"),
59 }
60 }
61
62 #[must_use]
64 pub const fn default_enabled() -> Self {
65 if cfg!(feature = "regular") {
66 Self::Regular
67 } else if cfg!(feature = "thin") {
68 Self::Thin
69 } else if cfg!(feature = "light") {
70 Self::Light
71 } else if cfg!(feature = "bold") {
72 Self::Bold
73 } else if cfg!(feature = "fill") {
74 Self::Fill
75 } else if cfg!(feature = "duotone") {
76 Self::Duotone
77 } else {
78 Self::Regular
81 }
82 }
83}
84
85impl std::fmt::Display for Weight {
86 fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
87 formatter.write_str(self.as_str())
88 }
89}