bnr_xfs/status/
position.rs1use std::fmt;
2
3pub const CDR_POS_TOP: u32 = 1;
4pub const CDR_POS_BOTTOM: u32 = 2;
5
6#[repr(u32)]
8#[derive(Clone, Copy, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
9pub enum CdrPosition {
10 Top = CDR_POS_TOP,
12 #[default]
14 Bottom = CDR_POS_BOTTOM,
15}
16
17impl CdrPosition {
18 pub const fn new() -> Self {
20 Self::Bottom
21 }
22
23 pub const fn create(val: u32) -> Self {
25 match val {
26 CDR_POS_BOTTOM => Self::Bottom,
27 CDR_POS_TOP => Self::Top,
28 _ => Self::Bottom,
29 }
30 }
31}
32
33impl From<&CdrPosition> for &'static str {
34 fn from(val: &CdrPosition) -> Self {
35 match val {
36 CdrPosition::Bottom => "bottom",
37 CdrPosition::Top => "top",
38 }
39 }
40}
41
42impl From<CdrPosition> for &'static str {
43 fn from(val: CdrPosition) -> Self {
44 (&val).into()
45 }
46}
47
48impl fmt::Display for CdrPosition {
49 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
50 write!(f, r#""{}""#, <&str>::from(self))
51 }
52}
53
54impl_xfs_enum!(CdrPosition, "position");