upc-a
A Rust library for parsing, validating, and working with UPC-A (Universal Product Code).
What is UPC-A?
UPC-A is a 12-digit number used to identify a product. Each UPC-A number consists of 11 digits plus a check digit. The check digit is calculated using a specific algorithm based on the first 11 digits.
Features
- Memory-efficient representation (8 bytes)
- Format-aware serialization/deserialization with serde
- Binary serialization support via bitcode
- Comprehensive error handling for invalid input
- No-std compatible, zero heap allocation
Usage
use UpcA;
use FromStr;
// From numeric UPC-A code
let upc_a = from_code?;
// From string representation using FromStr trait
let upc_a = from_str?;
// From a compact binary format
let upc_a = from_bytes?;
// Get the UPC-A code as a numeric value
assert_eq!;
// Display a UPC-A code
assert_eq!;
// Convert to a compact binary format
assert_eq!;
Serde integration
use UpcA;
use ;
// Define a struct with a UPC-A code
// For human-readable formats like JSON and TOML, ISRCs are serialized as strings
let json = r#"{"name":"Meme cat plush","upc_a":123456789012}"#;
let product: Product = from_str?;