tokio_listener/
unix_chmod.rs1use std::{fmt::Display, str::FromStr};
2
3#[cfg_attr(docsrs_alt, doc(cfg(feature = "unix_path_tools")))]
4#[cfg(feature = "unix_path_tools")]
5#[non_exhaustive]
7#[cfg_attr(
8 feature = "serde",
9 derive(serde_with::DeserializeFromStr, serde_with::SerializeDisplay)
10)]
11#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
12pub enum UnixChmodVariant {
13 Owner,
15 Group,
17 Everybody,
19}
20
21#[cfg(feature = "unix_path_tools")]
22#[cfg_attr(docsrs_alt, doc(cfg(feature = "unix_path_tools")))]
23impl Display for UnixChmodVariant {
24 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
25 match self {
26 UnixChmodVariant::Owner => "owner".fmt(f),
27 UnixChmodVariant::Group => "group".fmt(f),
28 UnixChmodVariant::Everybody => "everybody".fmt(f),
29 }
30 }
31}
32
33#[cfg(feature = "unix_path_tools")]
34#[cfg_attr(docsrs_alt, doc(cfg(feature = "unix_path_tools")))]
35impl FromStr for UnixChmodVariant {
36 type Err = &'static str;
37
38 fn from_str(s: &str) -> Result<Self, Self::Err> {
39 if s.eq_ignore_ascii_case("owner") {
40 Ok(UnixChmodVariant::Owner)
41 } else if s.eq_ignore_ascii_case("group") {
42 Ok(UnixChmodVariant::Group)
43 } else if s.eq_ignore_ascii_case("everybody") {
44 Ok(UnixChmodVariant::Everybody)
45 } else {
46 Err("Unknown chmod variant. Expected `owner`, `group` or `everybody`.")
47 }
48 }
49}