cat_dev/mion/proto/cgis/
status.rs1use crate::mion::cgis::MIONCGIApiError;
2use std::fmt::{Display, Formatter, Result as FmtResult};
3
4#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
6pub enum StatusOperation {
7 Eject,
8}
9
10impl Display for StatusOperation {
11 fn fmt(&self, fmt: &mut Formatter<'_>) -> FmtResult {
12 write!(fmt, "{}", Into::<&str>::into(self))
13 }
14}
15
16impl From<&StatusOperation> for &str {
17 fn from(value: &StatusOperation) -> Self {
18 match *value {
19 StatusOperation::Eject => "eject",
20 }
21 }
22}
23impl From<StatusOperation> for &str {
24 fn from(value: StatusOperation) -> Self {
25 Self::from(&value)
26 }
27}
28impl TryFrom<&str> for StatusOperation {
29 type Error = MIONCGIApiError;
32
33 fn try_from(value: &str) -> Result<Self, Self::Error> {
34 match value {
35 "eject" => Ok(Self::Eject),
36 val => Err(MIONCGIApiError::UnknownStatusOperation(val.to_owned())),
37 }
38 }
39}
40
41#[cfg(test)]
42mod unit_tests {
43 use super::*;
44
45 #[test]
46 pub fn round_trip_status_operation() {
47 for operation in vec![StatusOperation::Eject] {
48 assert_eq!(
49 StatusOperation::try_from(Into::<&str>::into(&operation)),
50 Ok(operation),
51 "Round-trip conversion of: [{operation}] was not successful!",
52 );
53 }
54 }
55}