5 releases
Uses new Rust 2024
| 0.1.4 | Feb 9, 2026 |
|---|---|
| 0.1.3 | Feb 9, 2026 |
| 0.1.2 | Feb 9, 2026 |
| 0.1.1 | Feb 8, 2026 |
| 0.1.0 | Feb 8, 2026 |
#1410 in Parser implementations
32 downloads per month
Used in 2 crates
31KB
513 lines
zpl_toolchain_profile
Printer profile crate for the ZPL toolchain. Defines the Profile struct and loading utilities that drive data-driven validation.
Part of the zpl-toolchain project.
Full guide: See
docs/PROFILE_GUIDE.mdfor the complete profile system reference — schema, printerGates semantics, DPI-dependent defaults, and custom profile creation.
Profile Schema
Profiles describe a printer's capabilities: resolution, page dimensions, speed/darkness ranges, hardware features, media capabilities, and memory/firmware info. The canonical schema lives in spec/schema/profile.schema.jsonc and is cross-validated by the spec-compiler.
{
"id": "zebra-generic-203",
"schema_version": "1.1.0",
"dpi": 203,
"page": { "width_dots": 812, "height_dots": 1218 },
"speed_range": { "min": 2, "max": 8 },
"darkness_range": { "min": 0, "max": 30 },
"features": {
"cutter": false, "peel": false, "rewinder": false,
"applicator": false, "rfid": false, "rtc": false,
"battery": false, "zbi": false, "lcd": false, "kiosk": false
},
"media": {
"print_method": "direct_thermal",
"supported_modes": ["T"],
"supported_tracking": ["N", "Y", "W", "M"]
},
"memory": {
"ram_kb": 32768,
"flash_kb": 65536
}
}
Structs
Profile— top-level printer profile with requiredid,schema_version,dpiand optionalpage,speed_range,darkness_range,features,media,memoryPage— page/label dimension constraints (width_dots,height_dotsasOption<u32>)Range— min/max range for numeric capabilities (min: u32,max: u32); validated thatmin <= maxon load. Constructors:Range::new(min, max)(panics ifmin > max) andRange::try_new(min, max) -> Option<Range>(returnsNoneif invalid)Features— hardware feature flags forprinterGatesenforcement (cutter,peel,rewinder,applicator,rfid,rtc,battery,zbi,lcd,kioskasOption<bool>); three-state semantics:true= has feature,false= lacks feature (triggers ZPL1402),None= unknown (gate skipped)Media— media capability descriptors (print_method,supported_modes,supported_trackingasOption)Memory— memory and firmware info (ram_kb,flash_kbasOption<u32>,firmware_versionasOption<String>)
Derives: Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq (Profile, Page, Features, Media, Memory); Range derives all except Default.
Gate Resolution
The validator resolves printerGates against Profile.features:
- Feature
true→ gate passes - Feature
false→ gate fails → ZPL1402 - Feature
None/featuresabsent → gate check skipped (no false positives)
Command-level gates emit errors; enum value-level gates emit warnings.
Usage
- CLI
--profile profiles/zebra-generic-203.jsonloads a profile and enablesprofileConstraintchecks (e.g.,^PWwidth ≤page.width_dots,~SDdarkness ≤darkness_range.max) andprinterGatesenforcement. load_profile_from_str()deserializes and validates structural invariants, returningProfileErroron failure.ProfileErrorhas two variants:InvalidJson(serde parse failure) andInvalidField(structural invariant violation such asmin > max, emptyid, DPI out of 100–600, non-positive page dimensions, speed outside 1–14, darkness outside 0–30, or non-positive memory).resolve_profile_field()in the validator maps dotted paths (e.g.,"page.width_dots") to profile values.- The
all_profile_constraint_fields_are_resolvabletest ensures the resolver covers every field referenced in command specs.
Shipped Profiles
profiles/zebra-generic-203.json— 203 dpi generic (4" printhead, 812×1218 dots, direct thermal, no cutter/RFID)profiles/zebra-generic-300.json— 300 dpi generic (4" printhead, 1218×1800 dots, direct thermal, no cutter/RFID)
Dependencies
~0.5–1.4MB
~30K SLoC