bnr_xfs/currency/
mix.rs

1use std::fmt;
2
3use crate::impl_xfs_enum;
4
5const ALGORITHM: u32 = 6041;
6const TABLE: u32 = 6042;
7const DENOM: u32 = 6043;
8const MIN_BILLS: u32 = 6044;
9const ALGORITHM_BASE: u32 = 6063;
10const OPTIMUM_CHANGE: u32 = 6064;
11
12/// Represents variants for mixing algorithms in different contexts of CDR operation.
13#[repr(u32)]
14#[derive(Clone, Copy, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
15pub enum MixNumber {
16    #[default]
17    Algorithm = ALGORITHM,
18    Table = TABLE,
19    Denom = DENOM,
20    MinBills = MIN_BILLS,
21    AlgorithmBase = ALGORITHM_BASE,
22    OptimumChange = OPTIMUM_CHANGE,
23}
24
25impl MixNumber {
26    /// Creates a new [MixNumber].
27    pub const fn new() -> Self {
28        Self::Algorithm
29    }
30
31    /// Creates a new [MixNumber] from the provided parameter.
32    pub const fn create(val: u32) -> Self {
33        match val {
34            ALGORITHM => Self::Algorithm,
35            TABLE => Self::Table,
36            DENOM => Self::Denom,
37            MIN_BILLS => Self::MinBills,
38            ALGORITHM_BASE => Self::AlgorithmBase,
39            OPTIMUM_CHANGE => Self::OptimumChange,
40            _ => Self::Algorithm,
41        }
42    }
43}
44
45impl From<&MixNumber> for &'static str {
46    fn from(val: &MixNumber) -> Self {
47        match val {
48            MixNumber::Algorithm => "algorithm",
49            MixNumber::Table => "table",
50            MixNumber::Denom => "denomination",
51            MixNumber::MinBills => "minimum bills",
52            MixNumber::AlgorithmBase => "algorithm base",
53            MixNumber::OptimumChange => "optimum change",
54        }
55    }
56}
57
58impl From<MixNumber> for &'static str {
59    fn from(val: MixNumber) -> Self {
60        (&val).into()
61    }
62}
63
64impl fmt::Display for MixNumber {
65    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
66        write!(f, r#""{}""#, <&str>::from(self))
67    }
68}
69
70impl_xfs_enum!(MixNumber, "mixNumber");