Barcoders is a barcode-encoding library for the Rust programming language.
Barcoders allows you to encode valid data for a chosen barcode symbology into a Vec<u8>
representation of the underlying binary structure. From here, you can take advantage of one of the optional builtin generators (for exporting to SVG, GIF, PNG, etc) or build your own.
Installation
For encode-only functionality (e.g if you just want to translate a String
into a Vec<u8>
of binary digits):
[]
= "0.3.5"
If you want to generate barcodes into a particular format, turn on the appropriate features:
[]
= { = "0.3.5", = ["image", "svg"]}
Each generator is an optional feature so you only need to compile what you want to use. See below for the feature associated to the generation functionality you desire.
Documentation
Documentation and examples are available here.
Current Support
The ultimate goal of Barcoders is to provide encoding support for all major (and many not-so-major) symbologies.
Symbologies
- EAN-13
- UPC-A
- JAN
- Bookland
- EAN-8
- EAN Supplementals
- EAN-2
- EAN-5
- Code39
- Two-Of-Five
- Interleaved (ITF)
- Standard (STF)
- More coming!
Generators
- ASCII (feature:
ascii
) - SVG (feature:
svg
) - PNG (feature:
image
) - GIF (feature:
image
) - JPEG (feature:
image
) - More coming! (PostScript, etc)
Examples
Encoding
extern crate barcoders;
use *;
// Each encoder accepts a String to be encoded. Valid data is barcode-specific
// and thus constructors return an Result<T, barcoders::error::Error>.
let barcode = EAN13 new.unwrap;
// The `encode` method returns a Vec<u8> of the binary representation of the
// generated barcode. This is useful if you want to add your own generator.
let encoded: = barcode.encode;
Image generation
extern crate barcoders;
use *;
use *;
use *;
use BufWriter;
use File;
use Path;
let barcode = new.unwrap;
let png = PNG;
let encoded = barcode.encode;
// Image generators return a Result<Vec<u8>, &str) of encoded bytes.
let bytes = png.generate.unwrap;
// Which you can then save to disk.
let file = create.unwrap;
let mut writer = new;
writer.write.unwrap;
// Generated file ↓ ↓ ↓
ASCII generation
extern crate barcoders;
use *;
use *;
let barcode = EAN13 new.unwrap;
let encoded = barcode.encode;
// The ASCII generator is useful for testing purposes.
let ascii = ASCII new;
ascii.generate;
assert_eq!;
Tests
Note, some of the image tests (intentionally) leave behind image files in ./target/debug that should be visually inspected for correctness.
Full suite:
$ cargo test --features="image svg ascii"
Encoding only:
$ cargo test