Expand description
UN/CEFACT Recommendation No. 20 — Codes for Units of Measure Used in International Trade (Revision 17, 2021).
All data is generated at compile time from rec20.xlsx and embedded as
static data. No runtime allocations, no I/O.
§Example
use cefact_units::UnitOfMeasure;
let kg = UnitOfMeasure::from_code("KGM").unwrap();
assert_eq!(kg.name(), "kilogram");
assert_eq!(kg.symbol(), Some("kg"));
assert_eq!(kg.quantity(), Some("mass"));
let parsed: UnitOfMeasure = "MTR".parse().unwrap();
assert_eq!(parsed.to_string(), "MTR");
for unit in UnitOfMeasure::ALL {
println!("{} — {}", unit.code(), unit.name());
}Structs§
- Unit
Info - All metadata for a
UnitOfMeasurevariant. - Unknown
Code - Error returned when parsing an unrecognised UN/CEFACT common code.
Enums§
- Unit
Code - Canonical UN/CEFACT common code (for example:
"MTR","KGM"). - Unit
OfMeasure - Every active UN/CEFACT unit of measure code (Rec 20, Rev 17 — 2021).