xio_base_datatypes/
module_state.rs

1use std::{fmt, io};
2use try_from::TryFrom;
3
4#[repr(u8)]
5#[derive(Clone, Debug, PartialEq)]
6pub enum ModuleState {
7    Uninitialized = 0,
8    Ready = 1,
9    Running = 2,
10    Error = 3,
11}
12
13impl TryFrom<u8> for ModuleState {
14    type Err = io::Error;
15    fn try_from(value: u8) -> io::Result<Self> {
16        match value {
17            0 => Ok(ModuleState::Uninitialized),
18            1 => Ok(ModuleState::Ready),
19            2 => Ok(ModuleState::Running),
20            3 => Ok(ModuleState::Error),
21            _ => Err(io::Error::new(
22                io::ErrorKind::InvalidData,
23                format!("Invalid ModuleState enum value {}", value),
24            )),
25        }
26    }
27}
28
29impl fmt::Display for ModuleState {
30    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
31        write!(f, "{:?}", self)
32    }
33}