bnr_xfs/status/
inter_stacker.rs

1use std::fmt;
2
3use super::HardwareStatus;
4
5pub const CDR_IS_EMPTY: u32 = 6185;
6pub const CDR_IS_NOT_EMPTY: u32 = 6186;
7pub const CDR_IS_UNKNOWN: u32 = 6187;
8
9/// Represents intermediate stacker status values.
10#[repr(u32)]
11#[derive(Clone, Copy, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
12pub enum IntermediateStackerStatus {
13    /// Indicates the stacker is empty
14    Empty = CDR_IS_EMPTY,
15    /// Indicates the stacker is not empty
16    NotEmpty = CDR_IS_NOT_EMPTY,
17    /// Indicates the stacker status is unknown
18    #[default]
19    Unknown = CDR_IS_UNKNOWN,
20}
21
22impl IntermediateStackerStatus {
23    /// Creates a new [IntermediateStackerStatus].
24    pub const fn new() -> Self {
25        Self::Unknown
26    }
27
28    /// Creates a new [IntermediateStackerStatus] from the provided parameter.
29    pub const fn create(val: u32) -> Self {
30        match val {
31            ds if ds == CDR_IS_EMPTY => Self::Empty,
32            ds if ds == CDR_IS_NOT_EMPTY => Self::NotEmpty,
33            ds if ds == CDR_IS_UNKNOWN => Self::Unknown,
34            _ => Self::Unknown,
35        }
36    }
37}
38
39impl From<IntermediateStackerStatus> for HardwareStatus {
40    fn from(val: IntermediateStackerStatus) -> Self {
41        match val {
42            IntermediateStackerStatus::Empty | IntermediateStackerStatus::NotEmpty => {
43                Self::Notification
44            }
45            IntermediateStackerStatus::Unknown => Self::Warning,
46        }
47    }
48}
49
50impl From<IntermediateStackerStatus> for &'static str {
51    fn from(val: IntermediateStackerStatus) -> Self {
52        match val {
53            IntermediateStackerStatus::Empty => "empty",
54            IntermediateStackerStatus::NotEmpty => "not empty",
55            IntermediateStackerStatus::Unknown => "unknown",
56        }
57    }
58}
59
60impl From<&IntermediateStackerStatus> for &'static str {
61    fn from(val: &IntermediateStackerStatus) -> Self {
62        (*val).into()
63    }
64}
65
66impl fmt::Display for IntermediateStackerStatus {
67    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
68        write!(f, "{}", <&str>::from(self))
69    }
70}
71
72impl_xfs_enum!(IntermediateStackerStatus, "intermediateStackerStatus");