1use cyfs_base::*;
2
3use std::str::FromStr;
4
5#[derive(Debug, Clone, Eq, PartialEq)]
6pub enum AclAccess {
7 Accept = 0,
8 Reject = 1,
9 Drop = 2,
10 Pass = 3,
11}
12
13impl AclAccess {
14 pub fn as_str(&self) -> &str {
15 match *self {
16 Self::Accept => "accept",
17 Self::Reject => "reject",
18 Self::Drop => "drop",
19 Self::Pass => "pass",
20 }
21 }
22}
23
24impl ToString for AclAccess {
25 fn to_string(&self) -> String {
26 self.as_str().to_owned()
27 }
28}
29
30impl FromStr for AclAccess {
31 type Err = BuckyError;
32
33 fn from_str(s: &str) -> Result<Self, Self::Err> {
34 let ret = match s {
35 "accept" => Self::Accept,
36 "reject" => Self::Reject,
37 "drop" => Self::Drop,
38 "pass" => Self::Pass,
39
40 _ => {
41 let msg = format!("unknown acl access: {}", s);
42 error!("{}", msg);
43 return Err(BuckyError::new(BuckyErrorCode::InvalidFormat, msg));
44 }
45 };
46
47 Ok(ret)
48 }
49}