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
52
use bee_common::packable::{Packable, Read, Write};
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("I/O error happened: {0:?}")]
Io(#[from] std::io::Error),
#[error("Unknown storage health variant: {0}")]
UnknownHealth(u8),
}
#[repr(u8)]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum StorageHealth {
Healthy = 0,
Idle = 1,
Corrupted = 2,
}
impl Packable for StorageHealth {
type Error = Error;
fn packed_len(&self) -> usize {
0u8.packed_len()
}
fn pack<W: Write>(&self, writer: &mut W) -> Result<(), Self::Error> {
(*self as u8).pack(writer)?;
Ok(())
}
fn unpack_inner<R: Read + ?Sized, const CHECK: bool>(reader: &mut R) -> Result<Self, Self::Error> {
match u8::unpack_inner::<R, CHECK>(reader)? {
0 => Ok(StorageHealth::Healthy),
1 => Ok(StorageHealth::Idle),
2 => Ok(StorageHealth::Corrupted),
h => Err(Error::UnknownHealth(h)),
}
}
}