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