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