Skip to main content

ZplError

Enum ZplError 

Source
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 (AZ) 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 })
);

Fields

§value: u16

The rejected width or height, in dots.

§thickness: u16

The line thickness the dimension was compared against, in dots.

Trait Implementations§

Source§

impl Clone for ZplError

Source§

fn clone(&self) -> ZplError

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ZplError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for ZplError

Source§

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for ZplError

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl PartialEq for ZplError

Source§

fn eq(&self, other: &ZplError) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for ZplError

Source§

impl StructuralPartialEq for ZplError

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.