bnr_xfs/capabilities/
cdr_type.rs

1use std::fmt;
2
3use crate::impl_xfs_enum;
4
5const CDR_TYPE_NONE: u32 = 6010;
6const CDR_TYPE_DISPENSER: u32 = 6011;
7const CDR_TYPE_RECYCLER: u32 = 6012;
8const CDR_TYPE_ATM: u32 = 6013;
9
10/// Types of CDR units.
11#[repr(u32)]
12#[derive(Clone, Copy, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
13pub enum CdrType {
14    #[default]
15    None = CDR_TYPE_NONE,
16    Dispenser = CDR_TYPE_DISPENSER,
17    Recycler = CDR_TYPE_RECYCLER,
18    Atm = CDR_TYPE_ATM,
19}
20
21impl CdrType {
22    /// Creates a new [CdrType].
23    pub const fn new() -> Self {
24        Self::None
25    }
26
27    /// Creates a new [CdrType] from the provided parameter.
28    pub const fn create(val: u32) -> Self {
29        match val {
30            CDR_TYPE_NONE => Self::None,
31            CDR_TYPE_DISPENSER => Self::Dispenser,
32            CDR_TYPE_RECYCLER => Self::Recycler,
33            CDR_TYPE_ATM => Self::Atm,
34            _ => Self::None,
35        }
36    }
37}
38
39impl From<&CdrType> for &'static str {
40    fn from(val: &CdrType) -> Self {
41        match val {
42            CdrType::None => "none",
43            CdrType::Dispenser => "dispenser",
44            CdrType::Recycler => "recycler",
45            CdrType::Atm => "atm",
46        }
47    }
48}
49
50impl From<CdrType> for &'static str {
51    fn from(val: CdrType) -> Self {
52        (&val).into()
53    }
54}
55
56impl fmt::Display for CdrType {
57    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
58        write!(f, r#""{}""#, <&str>::from(self))
59    }
60}
61
62impl_xfs_enum!(CdrType, "cdType");