bnr_xfs/cash_unit/
number.rs

1use std::fmt;
2
3use crate::impl_xfs_i4;
4
5/// Represents a CU ID number.
6#[repr(C)]
7#[derive(Clone, Copy, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
8pub struct Number(u32);
9
10impl Number {
11    /// Creates a new [Number].
12    pub const fn new() -> Self {
13        Self(0)
14    }
15
16    /// Creates a new [Number] from the provided parameter.
17    pub const fn create(val: u32) -> Self {
18        Self(val)
19    }
20
21    /// Gets the inner representation of the [Number].
22    pub const fn inner(&self) -> u32 {
23        self.0
24    }
25
26    /// Sets the inner representation of the [Number].
27    pub fn set_inner(&mut self, val: u32) {
28        self.0 = val;
29    }
30
31    /// Converts into the inner representation of the [Number].
32    pub fn into_inner(self) -> u32 {
33        self.0
34    }
35}
36
37impl fmt::Display for Number {
38    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
39        write!(f, "{}", self.inner())
40    }
41}
42
43impl_xfs_i4!(Number, "number");