bnr_xfs/cash_unit/threshold/
mode.rs1use std::fmt;
2
3use crate::impl_xfs_enum;
4
5const THRESHOLD_SENSOR: u32 = 0;
6const THRESHOLD_COUNT: u32 = 1;
7
8#[repr(u32)]
10#[derive(Clone, Copy, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
11pub enum ThresholdMode {
12 #[default]
14 Sensor = THRESHOLD_SENSOR,
15 Count = THRESHOLD_COUNT,
17}
18
19impl ThresholdMode {
20 pub const fn new() -> Self {
22 Self::Sensor
23 }
24
25 pub const fn create(val: u32) -> Self {
27 match val {
28 THRESHOLD_SENSOR => Self::Sensor,
29 THRESHOLD_COUNT => Self::Count,
30 _ => Self::Sensor,
31 }
32 }
33}
34
35impl From<&ThresholdMode> for &'static str {
36 fn from(val: &ThresholdMode) -> Self {
37 match val {
38 ThresholdMode::Sensor => "sensor",
39 ThresholdMode::Count => "count",
40 }
41 }
42}
43
44impl From<ThresholdMode> for &'static str {
45 fn from(val: ThresholdMode) -> Self {
46 (&val).into()
47 }
48}
49
50impl fmt::Display for ThresholdMode {
51 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
52 write!(f, r#""{}""#, <&str>::from(self))
53 }
54}
55
56impl_xfs_enum!(ThresholdMode, "thresholdMode");