bnr_xfs/status/
content.rs1use std::fmt;
2
3use super::HardwareStatus;
4
5pub const CT_EMPTY: u32 = 0;
6pub const CT_NOT_EMPTY: u32 = 1;
7
8#[repr(u32)]
10#[derive(Clone, Copy, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
11pub enum ContentStatus {
12 #[default]
14 Empty = CT_EMPTY,
15 NotEmpty = CT_NOT_EMPTY,
17}
18
19impl ContentStatus {
20 pub const fn new() -> Self {
22 Self::Empty
23 }
24
25 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");