cyfs_lib/rmeta/def/
config.rs1use super::path::GlobalStatePathHelper;
2use cyfs_base::*;
3
4use serde::{Deserialize, Deserializer, Serialize, Serializer};
5
6#[repr(u8)]
7#[derive(Clone, Copy, Debug, Eq, PartialEq)]
8pub enum GlobalStatePathStorageState {
9 Concrete = 0,
10 Virtual = 1,
11}
12
13impl Into<u8> for GlobalStatePathStorageState {
14 fn into(self) -> u8 {
15 unsafe { std::mem::transmute(self as u8) }
16 }
17}
18
19impl std::convert::TryFrom<u8> for GlobalStatePathStorageState {
20 type Error = BuckyError;
21 fn try_from(value: u8) -> Result<Self, Self::Error> {
22 let ret = match value {
23 0 => Self::Concrete,
24 1 => Self::Virtual,
25 _ => {
26 let msg = format!("unknown GlobalStatePathStorageState value: {}", value);
27 error!("{}", msg);
28 return Err(BuckyError::new(BuckyErrorCode::InvalidData, msg));
29 }
30 };
31
32 Ok(ret)
33 }
34}
35
36impl Serialize for GlobalStatePathStorageState {
37 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
38 where
39 S: Serializer,
40 {
41 serializer.serialize_u8(self.clone().into())
42 }
43}
44
45impl<'de> Deserialize<'de> for GlobalStatePathStorageState {
46 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
47 where
48 D: Deserializer<'de>,
49 {
50 deserializer.deserialize_u8(TU8Visitor::<Self>::new())
51 }
52}
53
54#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)]
55pub struct GlobalStatePathConfigItem {
56 pub path: String,
57
58 pub storage_state: Option<GlobalStatePathStorageState>,
60
61 pub depth: Option<u8>,
63}
64
65impl GlobalStatePathConfigItem {
66 pub fn try_fix_path(&mut self) {
67 self.path = GlobalStatePathHelper::fix_path(&self.path).to_string();
68 }
69}
70
71pub struct GlobalStatePathConfigItemValue {
72 pub storage_state: Option<GlobalStatePathStorageState>,
73 pub depth: Option<u8>,
74}