use std::{fmt::Display, str::FromStr};
#[cfg_attr(docsrs_alt, doc(cfg(feature = "unix_path_tools")))]
#[cfg(feature = "unix_path_tools")]
#[non_exhaustive]
#[cfg_attr(
feature = "serde",
derive(serde_with::DeserializeFromStr, serde_with::SerializeDisplay)
)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum UnixChmodVariant {
Owner,
Group,
Everybody,
}
#[cfg(feature = "unix_path_tools")]
#[cfg_attr(docsrs_alt, doc(cfg(feature = "unix_path_tools")))]
impl Display for UnixChmodVariant {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
UnixChmodVariant::Owner => "owner".fmt(f),
UnixChmodVariant::Group => "group".fmt(f),
UnixChmodVariant::Everybody => "everybody".fmt(f),
}
}
}
#[cfg(feature = "unix_path_tools")]
#[cfg_attr(docsrs_alt, doc(cfg(feature = "unix_path_tools")))]
impl FromStr for UnixChmodVariant {
type Err = &'static str;
fn from_str(s: &str) -> Result<Self, Self::Err> {
if s.eq_ignore_ascii_case("owner") {
Ok(UnixChmodVariant::Owner)
} else if s.eq_ignore_ascii_case("group") {
Ok(UnixChmodVariant::Group)
} else if s.eq_ignore_ascii_case("everybody") {
Ok(UnixChmodVariant::Everybody)
} else {
Err("Unknown chmod variant. Expected `owner`, `group` or `everybody`.")
}
}
}