#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub enum Weight {
#[default]
Regular,
Thin,
Light,
Bold,
Fill,
Duotone,
}
impl Weight {
pub const ALL: [Self; 6] = [
Self::Regular,
Self::Thin,
Self::Light,
Self::Bold,
Self::Fill,
Self::Duotone,
];
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::Regular => "regular",
Self::Thin => "thin",
Self::Light => "light",
Self::Bold => "bold",
Self::Fill => "fill",
Self::Duotone => "duotone",
}
}
#[must_use]
pub fn from_name(name: &str) -> Option<Self> {
Self::ALL.into_iter().find(|weight| weight.as_str() == name)
}
#[must_use]
pub const fn is_enabled(self) -> bool {
match self {
Self::Regular => cfg!(feature = "regular"),
Self::Thin => cfg!(feature = "thin"),
Self::Light => cfg!(feature = "light"),
Self::Bold => cfg!(feature = "bold"),
Self::Fill => cfg!(feature = "fill"),
Self::Duotone => cfg!(feature = "duotone"),
}
}
#[must_use]
pub const fn default_enabled() -> Self {
if cfg!(feature = "regular") {
Self::Regular
} else if cfg!(feature = "thin") {
Self::Thin
} else if cfg!(feature = "light") {
Self::Light
} else if cfg!(feature = "bold") {
Self::Bold
} else if cfg!(feature = "fill") {
Self::Fill
} else if cfg!(feature = "duotone") {
Self::Duotone
} else {
Self::Regular
}
}
}
impl std::fmt::Display for Weight {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
formatter.write_str(self.as_str())
}
}