Expand description
Generate package tracking IDs and render them as barcodes.
use smart_package_tracker::{Barcode, RenderOptions, TrackingId};
// 1. Mint an identifier.
let id = TrackingId::generate()?; // e.g. PKG-9ED9285C
// 2. Encode it as a Code 128 barcode.
let barcode = Barcode::code128(&id)?;
// 3. Export it.
let options = RenderOptions::default(); // 300 dpi, 13 mil, 25 mm tall
let png: Vec<u8> = barcode.to_png(&options)?;
let svg: String = barcode.to_svg(&options)?;
assert_eq!(&png[..8], b"\x89PNG\r\n\x1a\n");
assert!(svg.contains("<svg"));§Design
The pipeline has two independent halves, joined by a dimension-agnostic bit grid:
TrackingId ──▶ Symbology::encode ──▶ Symbol ──▶ Renderer::render ──▶ bytes
(Code 128 | QR) (BitMatrix) (Png | Svg)A linear barcode is a one-row BitMatrix; a matrix
symbology such as QR is a square one. Because renderers consume the grid
rather than the symbology, adding a format means implementing
Symbology and nothing else — QR support landed
without a single change to the PNG or SVG renderers.
Both renderers share one Layout calculation, so PNG and
SVG output describe identical geometry at identical physical size.
§Choosing an entropy width
TrackingId::generate defaults to 32 bits of randomness — the familiar
PKG-9ED9285C shape — which collides with ~69% probability once 100,000
IDs have been issued. Production systems should configure 64 bits:
use smart_package_tracker::{Checksum, IdGenerator};
let generator = IdGenerator::builder()
.entropy_bits(64)
.checksum(Checksum::Iso7064Mod37_36)
.build()?;See IdGenerator for the full collision table.
§Feature flags
| Feature | Default | Effect |
|---|---|---|
std | yes | File helpers and std::error::Error. Without it the crate is no_std + alloc. |
os-rng | yes | Seed IDs from the OS CSPRNG. Turn off on targets getrandom does not support; IdGenerator::generate_from_entropy still works. |
code128 | yes | Code 128 encoding and decoding. |
qr | yes | QR Code encoding. Implies std. |
png | yes | PNG rendering. Implies std. |
svg | yes | SVG rendering. No extra dependencies. |
serde | no | Serialize/Deserialize for the public data types. |
§Not yet implemented
Image scanning, shipment events, and carrier integrations are deliberately
absent. The Symbology and
Renderer traits are the extension points for new
formats; carrier integrations belong in separate crates, so that network
I/O and vendor licence terms stay out of this dependency graph.
QR Code is a registered trademark of Denso Wave Incorporated.
Re-exports§
pub use error::Error;pub use error::Result;pub use id::Checksum;pub use id::IdGenerator;pub use id::IdGeneratorBuilder;pub use id::TrackingId;pub use render::hri_supports;pub use render::Color;pub use render::Length;pub use render::QuietZone;pub use render::RenderOptions;pub use render::RenderOptionsBuilder;pub use symbology::Symbol;pub use symbology::SymbologyKind;pub use symbology::Code128;code128pub use symbology::Ecc;qrpub use symbology::Qr;qrpub use symbology::QrVersion;qr
Modules§
- error
- Error types for this crate.
- id
- Tracking identifiers.
- render
- Turning
Symbols into images. - symbology
- Turning payloads into bit patterns.
Structs§
- Barcode
- An encoded barcode, ready to render.