1#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
4#[derive(Clone, Copy, Debug, PartialEq, Eq)]
5pub enum Access {
6 #[cfg_attr(feature = "serde", serde(rename = "read-only"))]
8 ReadOnly,
9
10 #[cfg_attr(feature = "serde", serde(rename = "read-write"))]
12 ReadWrite,
13
14 #[cfg_attr(feature = "serde", serde(rename = "read-writeOnce"))]
18 ReadWriteOnce,
19
20 #[cfg_attr(feature = "serde", serde(rename = "writeOnce"))]
23 WriteOnce,
24
25 #[cfg_attr(feature = "serde", serde(rename = "write-only"))]
27 WriteOnly,
28}
29
30impl Access {
31 pub fn can_read(self) -> bool {
33 matches!(self, Self::ReadOnly | Self::ReadWrite | Self::ReadWriteOnce)
34 }
35
36 pub fn can_write(self) -> bool {
38 !matches!(self, Self::ReadOnly)
39 }
40}
41
42impl Default for Access {
43 fn default() -> Self {
44 Self::ReadWrite
45 }
46}
47
48impl Access {
49 pub fn parse_str(s: &str) -> Option<Self> {
51 match s {
52 "read-only" => Some(Self::ReadOnly),
53 "read-write" => Some(Self::ReadWrite),
54 "read-writeOnce" => Some(Self::ReadWriteOnce),
55 "write-only" => Some(Self::WriteOnly),
56 "writeOnce" => Some(Self::WriteOnce),
57 _ => None,
58 }
59 }
60
61 pub const fn as_str(self) -> &'static str {
63 match self {
64 Self::ReadOnly => "read-only",
65 Self::ReadWrite => "read-write",
66 Self::ReadWriteOnce => "read-writeOnce",
67 Self::WriteOnly => "write-only",
68 Self::WriteOnce => "writeOnce",
69 }
70 }
71}