Skip to main content

zpl_forge/ast/
commons.rs

1/// 1-D barcode symbologies that share the generic rendering pipeline.
2#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
3pub enum Barcode1DKind {
4    /// `^BE` — EAN-13 (retail).
5    Ean13,
6    /// `^BU` — UPC-A (retail).
7    UpcA,
8    /// `^B2` — Interleaved 2 of 5 (cartons, ITF-14).
9    Interleaved2of5,
10    /// `^BA` — Code 93.
11    Code93,
12}
13
14/// Represents text justification options in ZPL.
15#[derive(Debug, Clone, Copy, PartialEq)]
16pub enum Justification {
17    /// Left justification (Default)
18    L,
19    /// Center justification
20    C,
21    /// Right justification
22    R,
23    /// Justified (full width)
24    J,
25}
26
27impl From<char> for Justification {
28    fn from(value: char) -> Self {
29        match value {
30            'L' => Justification::L,
31            'C' => Justification::C,
32            'R' => Justification::R,
33            'J' => Justification::J,
34            _ => {
35                #[cfg(feature = "tracing")]
36                tracing::debug!(
37                    target: crate::TARGET,
38                    "{} is not a valid Justification value, using L as default",
39                    value
40                );
41                Justification::L
42            }
43        }
44    }
45}
46
47impl From<Justification> for char {
48    fn from(value: Justification) -> Self {
49        match value {
50            Justification::L => 'L',
51            Justification::C => 'C',
52            Justification::R => 'R',
53            Justification::J => 'J',
54        }
55    }
56}
57
58impl From<Justification> for String {
59    fn from(value: Justification) -> Self {
60        let c: char = value.into();
61        c.to_string()
62    }
63}
64
65/// Represents a boolean-like state in ZPL (Yes/No).
66#[derive(Debug, Clone, Copy, PartialEq)]
67pub enum YesNo {
68    /// Yes ('Y')
69    Y,
70    /// No ('N')
71    N,
72}
73
74impl From<char> for YesNo {
75    fn from(value: char) -> Self {
76        match value {
77            'Y' => YesNo::Y,
78            'N' => YesNo::N,
79            _ => {
80                #[cfg(feature = "tracing")]
81                tracing::debug!(
82                    target: crate::TARGET,
83                    "{} is not a valid YesNo value, using N as default",
84                    value
85                );
86                YesNo::N
87            }
88        }
89    }
90}
91
92impl From<YesNo> for char {
93    fn from(value: YesNo) -> Self {
94        match value {
95            YesNo::Y => 'Y',
96            YesNo::N => 'N',
97        }
98    }
99}
100
101impl From<bool> for YesNo {
102    fn from(value: bool) -> Self {
103        if value { YesNo::Y } else { YesNo::N }
104    }
105}
106
107impl From<YesNo> for bool {
108    fn from(value: YesNo) -> Self {
109        match value {
110            YesNo::Y => true,
111            YesNo::N => false,
112        }
113    }
114}