pub enum ZplError {
InvalidPosition(u16),
InvalidFontSize(u16),
InvalidBarcodeWidth(u8),
InvalidWidthRatio(f32),
InvalidBarcodeHeight(u16),
InvalidThickness(u16),
InvalidGraphicDimension(u16),
InvalidRounding(u8),
InvalidFont(char),
InvalidBoxDimension {
value: u16,
thickness: u16,
},
}Expand description
Errors that can occur when building a ZPL label.
Every method on the builder validates its arguments before adding an element to the label. When a value falls outside the range accepted by the ZPL specification, the method returns the corresponding variant of this error instead of silently producing an invalid command string.
§Example
use zpl_builder::{LabelBuilder, Orientation, ZplError};
let result = LabelBuilder::new()
.add_text("Hello", 0, 0, '0', 15, Orientation::Normal); // '0' is not a valid font
assert_eq!(result, Err(ZplError::InvalidFont('0')));Variants§
InvalidPosition(u16)
A position value (x or y axis) is outside the range 0–32000.
ZPL positions are expressed in dots. The maximum addressable coordinate on either axis is 32000 dots.
The inner value is the rejected position.
§Example
use zpl_builder::{LabelBuilder, ZplError};
assert_eq!(
LabelBuilder::new().set_home_position(32001, 0),
Err(ZplError::InvalidPosition(32001))
);InvalidFontSize(u16)
A font size is outside the range 10–32000.
Font sizes are expressed in dots. Values below 10 are not accepted by the ZPL specification.
The inner value is the rejected font size.
§Example
use zpl_builder::{LabelBuilder, Orientation, ZplError};
assert_eq!(
LabelBuilder::new().add_text("x", 0, 0, 'A', 9, Orientation::Normal),
Err(ZplError::InvalidFontSize(9))
);InvalidBarcodeWidth(u8)
A barcode bar width is outside the range 1–10.
The bar width controls the width of the narrowest bar in the barcode, expressed in dots.
The inner value is the rejected width.
§Example
use zpl_builder::{BarcodeType, LabelBuilder, Orientation, ZplError};
assert_eq!(
LabelBuilder::new().add_barcode(BarcodeType::Code128, "x", 0, 0, 11, 2.5, 10, Orientation::Normal),
Err(ZplError::InvalidBarcodeWidth(11))
);InvalidWidthRatio(f32)
A barcode wide-to-narrow bar width ratio is outside the range 2.0–3.0.
The ratio must be a multiple of 0.1. It has no effect on fixed-ratio
barcode types.
The inner value is the rejected ratio as originally supplied by the caller.
§Example
use zpl_builder::{BarcodeType, LabelBuilder, Orientation, ZplError};
assert_eq!(
LabelBuilder::new().add_barcode(BarcodeType::Code39, "x", 0, 0, 2, 1.5, 10, Orientation::Normal),
Err(ZplError::InvalidWidthRatio(1.5))
);InvalidBarcodeHeight(u16)
A barcode height is outside the range 1–32000.
The height is expressed in dots.
The inner value is the rejected height.
§Example
use zpl_builder::{BarcodeType, LabelBuilder, Orientation, ZplError};
assert_eq!(
LabelBuilder::new().add_barcode(BarcodeType::Code128, "x", 0, 0, 2, 2.5, 0, Orientation::Normal),
Err(ZplError::InvalidBarcodeHeight(0))
);InvalidThickness(u16)
A line thickness is outside the range 1–32000.
The thickness is expressed in dots and applies to boxes, circles and ellipses.
The inner value is the rejected thickness.
§Example
use zpl_builder::{Color, LabelBuilder, ZplError};
assert_eq!(
LabelBuilder::new().add_graphical_box(0, 0, 100, 100, 0, Color::Black, 0),
Err(ZplError::InvalidThickness(0))
);InvalidGraphicDimension(u16)
A graphical dimension (diameter, width or height of a circle or ellipse)
is outside the range 3–4095.
The dimension is expressed in dots.
The inner value is the rejected dimension.
§Example
use zpl_builder::{Color, LabelBuilder, ZplError};
assert_eq!(
LabelBuilder::new().add_graphical_circle(0, 0, 2, 1, Color::Black),
Err(ZplError::InvalidGraphicDimension(2))
);InvalidRounding(u8)
A corner rounding value is outside the range 0–8.
0 produces sharp corners. 8 produces the most rounded corners.
The inner value is the rejected rounding.
§Example
use zpl_builder::{Color, LabelBuilder, ZplError};
assert_eq!(
LabelBuilder::new().add_graphical_box(0, 0, 100, 100, 1, Color::Black, 9),
Err(ZplError::InvalidRounding(9))
);InvalidFont(char)
A font identifier is not a valid ZPL font name.
Valid font names are a single ASCII uppercase letter (A–Z) or a
digit from 1 to 9. The digit 0 (zero) is not a valid font name.
The inner value is the rejected character.
§Example
use zpl_builder::{LabelBuilder, Orientation, ZplError};
assert_eq!(
LabelBuilder::new().add_text("x", 0, 0, '0', 10, Orientation::Normal),
Err(ZplError::InvalidFont('0'))
);InvalidBoxDimension
A box width or height is smaller than the box thickness.
ZPL requires that the width and height of a graphical box each be at least equal to its line thickness, otherwise the box cannot be rendered.
§Fields
value— the rejected width or height, in dots.thickness— the thickness the dimension was compared against, in dots.
§Example
use zpl_builder::{Color, LabelBuilder, ZplError};
// thickness = 5, width = 2 → width < thickness
assert_eq!(
LabelBuilder::new().add_graphical_box(0, 0, 2, 100, 5, Color::Black, 0),
Err(ZplError::InvalidBoxDimension { value: 2, thickness: 5 })
);Trait Implementations§
Source§impl Error for ZplError
impl Error for ZplError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()