bnr_xfs/status/
content.rs

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