Crates.io | gtin-validate |
lib.rs | gtin-validate |
version | 1.3.0 |
source | src |
created_at | 2016-05-31 20:10:51.000984 |
updated_at | 2020-01-19 23:14:39.104589 |
description | Validate GTIN barcodes including UPC-A and EAN-13. This module has built-in support for GTIN-8, GTIN-12 (UPC-A), GTIN-13 (EAN-13), and GTIN-14 codes. |
homepage | |
repository | https://github.com/austinhartzheim/rust-gtin-validate/ |
max_upload_size | |
id | 5251 |
size | 39,689 |
Validate and correct GTIN codes, such as UPC-A and EAN-13, in Rust.
Currently supported types:
Validation features include:
Correction features include:
For full details, check the documentation.
Briefly, here are the function declarations:
// return true if the code is valid, false otherwise
fn gtin8::check(code: &str) -> bool;
fn gtin12::check(code: &str) -> bool;
fn gtin13::check(code: &str) -> bool;
fn gtin14::check(code: &str) -> bool;
// return a corrected String or Err
fn gtin8::fix(code: &str) -> Result<String, FixError>;
fn gtin12::fix(code: &str) -> Result<String, FixError>;
fn gtin13::fix(code: &str) -> Result<String, FixError>;
fn gtin14::fix(code: &str) -> Result<String, FixError>;
For example, you can validate UPC-A codes:
use gtin_validate::gtin12;
assert_eq!(gtin12::check("000000000000"), true);
assert_eq!(gtin12::check("000000000001"), false);
You can add this line to your Cargo.toml file:
[dependencies]
gtin-validate = "1.3.0"
Found a bug? Report an issue through GitHub.
Want to hack on the code? Submit a pull request.