bnr_xfs/cash_unit/
lock.rs

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