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    /// `^B8` — EAN-8 (short retail).
7    Ean8,
8    /// `^BU` — UPC-A (retail).
9    UpcA,
10    /// `^B9` — UPC-E (zero-suppressed retail).
11    UpcE,
12    /// `^B2` — Interleaved 2 of 5 (cartons, ITF-14).
13    Interleaved2of5,
14    /// `^BA` — Code 93.
15    Code93,
16    /// `^BB` — Codabar.
17    Codabar,
18    /// `^BM` — MSI / Modified Plessey.
19    Msi,
20    /// `^BZ` — POSTNET.
21    Postnet,
22    /// `^BR` — GS1 DataBar / RSS.
23    GS1DataBar,
24    /// `^BS` — UPC/EAN 2 and 5 digit supplemental extensions.
25    Extension25,
26}
27
28/// Represents text justification options in ZPL.
29#[derive(Debug, Clone, Copy, PartialEq)]
30pub enum Justification {
31    /// Left justification (Default)
32    L,
33    /// Center justification
34    C,
35    /// Right justification
36    R,
37    /// Justified (full width)
38    J,
39}
40
41impl From<char> for Justification {
42    fn from(value: char) -> Self {
43        match value {
44            'L' => Justification::L,
45            'C' => Justification::C,
46            'R' => Justification::R,
47            'J' => Justification::J,
48            _ => {
49                #[cfg(feature = "tracing")]
50                tracing::debug!(
51                    target: crate::TARGET,
52                    "{} is not a valid Justification value, using L as default",
53                    value
54                );
55                Justification::L
56            }
57        }
58    }
59}
60
61impl From<Justification> for char {
62    fn from(value: Justification) -> Self {
63        match value {
64            Justification::L => 'L',
65            Justification::C => 'C',
66            Justification::R => 'R',
67            Justification::J => 'J',
68        }
69    }
70}
71
72impl From<Justification> for String {
73    fn from(value: Justification) -> Self {
74        let c: char = value.into();
75        c.to_string()
76    }
77}
78
79/// Represents a boolean-like state in ZPL (Yes/No).
80#[derive(Debug, Clone, Copy, PartialEq)]
81pub enum YesNo {
82    /// Yes ('Y')
83    Y,
84    /// No ('N')
85    N,
86}
87
88impl From<char> for YesNo {
89    fn from(value: char) -> Self {
90        match value {
91            'Y' => YesNo::Y,
92            'N' => YesNo::N,
93            _ => {
94                #[cfg(feature = "tracing")]
95                tracing::debug!(
96                    target: crate::TARGET,
97                    "{} is not a valid YesNo value, using N as default",
98                    value
99                );
100                YesNo::N
101            }
102        }
103    }
104}
105
106impl From<YesNo> for char {
107    fn from(value: YesNo) -> Self {
108        match value {
109            YesNo::Y => 'Y',
110            YesNo::N => 'N',
111        }
112    }
113}
114
115impl From<bool> for YesNo {
116    fn from(value: bool) -> Self {
117        if value { YesNo::Y } else { YesNo::N }
118    }
119}
120
121impl From<YesNo> for bool {
122    fn from(value: YesNo) -> Self {
123        match value {
124            YesNo::Y => true,
125            YesNo::N => false,
126        }
127    }
128}