ach_util/
state.rs

1pub type AtomicMemoryState = atomic::Atomic<MemoryState>;
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
4pub enum MemoryState {
5    Uninitialized = 0,
6    Initializing = 1,
7    Initialized = 2,
8    Erasing = 3,
9    /// 被多次借用时,获取独占权
10    Regaining = 5,
11    Unknown,
12}
13impl MemoryState {
14    pub fn is_uninitialized(&self) -> bool {
15        self == &Self::Uninitialized
16    }
17    pub fn is_initializing(&self) -> bool {
18        self == &Self::Initializing
19    }
20    pub fn is_initialized(&self) -> bool {
21        self == &Self::Initialized
22    }
23    pub fn is_erasing(&self) -> bool {
24        self == &Self::Erasing
25    }
26    pub fn is_regaining(&self) -> bool {
27        self == &Self::Regaining
28    }
29    pub fn is_unknown(&self) -> bool {
30        self == &Self::Unknown
31    }
32    pub fn is_transient(&self) -> bool {
33        self == &Self::Initializing || self == &Self::Erasing || self == &Self::Regaining
34    }
35}
36impl From<u8> for MemoryState {
37    fn from(s: u8) -> Self {
38        match s {
39            s if s == MemoryState::Uninitialized as u8 => MemoryState::Uninitialized,
40            s if s == MemoryState::Initializing as u8 => MemoryState::Initializing,
41            s if s == MemoryState::Initialized as u8 => MemoryState::Initialized,
42            s if s == MemoryState::Erasing as u8 => MemoryState::Erasing,
43            s if s == MemoryState::Regaining as u8 => MemoryState::Regaining,
44            _ => MemoryState::Unknown,
45        }
46    }
47}
48impl From<MemoryState> for u8 {
49    fn from(s: MemoryState) -> Self {
50        s as u8
51    }
52}