cyfs_lib/rmeta/def/
def.rs1use cyfs_base::*;
2
3use std::str::FromStr;
4
5
6#[derive(Debug, Eq, PartialEq)]
7pub enum MetaAction {
8 GlobalStateAddAccess,
9 GlobalStateRemoveAccess,
10 GlobalStateClearAccess,
11
12 GlobalStateAddLink,
13 GlobalStateRemoveLink,
14 GlobalStateClearLink,
15
16 GlobalStateAddObjectMeta,
17 GlobalStateRemoveObjectMeta,
18 GlobalStateClearObjectMeta,
19
20 GlobalStateAddPathConfig,
21 GlobalStateRemovePathConfig,
22 GlobalStateClearPathConfig,
23}
24
25impl ToString for MetaAction {
26 fn to_string(&self) -> String {
27 (match *self {
28 Self::GlobalStateAddAccess => "global-state-add-access",
29 Self::GlobalStateRemoveAccess => "global-state-remove-access",
30 Self::GlobalStateClearAccess => "global-state-clear-access",
31
32 Self::GlobalStateAddLink => "global-state-add-link",
33 Self::GlobalStateRemoveLink => "global-state-remove-link",
34 Self::GlobalStateClearLink => "global-state-clear-link",
35
36 Self::GlobalStateAddObjectMeta => "global-state-add-object-meta",
37 Self::GlobalStateRemoveObjectMeta => "global-state-remove-object-meta",
38 Self::GlobalStateClearObjectMeta => "global-state-clear-object-meta",
39
40 Self::GlobalStateAddPathConfig => "global-state-add-path-config",
41 Self::GlobalStateRemovePathConfig => "global-state-remove-path-config",
42 Self::GlobalStateClearPathConfig => "global-state-clear-path-config",
43 })
44 .to_owned()
45 }
46}
47
48impl FromStr for MetaAction {
49 type Err = BuckyError;
50
51 fn from_str(value: &str) -> Result<Self, Self::Err> {
52 let ret = match value {
53 "global-state-add-access" => Self::GlobalStateAddAccess,
54 "global-state-remove-access" => Self::GlobalStateRemoveAccess,
55 "global-state-clear-access" => Self::GlobalStateClearAccess,
56
57 "global-state-add-link" => Self::GlobalStateAddLink,
58 "global-state-remove-link" => Self::GlobalStateRemoveLink,
59 "global-state-clear-link" => Self::GlobalStateClearLink,
60
61 "global-state-add-object-meta" => Self::GlobalStateAddObjectMeta,
62 "global-state-remove-object-meta" => Self::GlobalStateRemoveObjectMeta,
63 "global-state-clear-object-meta" => Self::GlobalStateClearObjectMeta,
64
65 "global-state-add-path-config" => Self::GlobalStateAddPathConfig,
66 "global-state-remove-path-config" => Self::GlobalStateRemovePathConfig,
67 "global-state-clear-path-config" => Self::GlobalStateClearPathConfig,
68
69 v @ _ => {
70 let msg = format!("unknown meta action: {}", v);
71 error!("{}", msg);
72
73 return Err(BuckyError::new(BuckyErrorCode::InvalidData, msg));
74 }
75 };
76
77 Ok(ret)
78 }
79}