gnu-units
Safe Rust bindings for the GNU units conversion library.
This crate provides a high-level Rust API over the vendored GNU units C library, enabling dimensional analysis and unit conversion without spawning external processes.
Features
- Parse and convert between thousands of units (length, mass, time, currency, etc.)
- Dimensionless factor extraction
- Conformability checking between units
- List all known unit definitions
- Optional Rust-native currency rate updates (
currency-updatefeature) - Statically links vendored GNU units with no system dependencies
Usage
[]
= "0.1"
use ;
// Simple conversion factor
let factor = convert.unwrap;
assert!;
// Conversion with a value
let km_val = 5.0;
let miles_val = km_val * convert.unwrap;
// Parse and inspect a unit
let unit = parse.unwrap;
println!; // "kg m / s s"
// Check conformability
let a = parse.unwrap;
let b = parse.unwrap;
assert!;
// Find all conformable units
let lengths = conformable.unwrap;
assert!;
Optional features
| Feature | Description |
|---|---|
vendored (default) |
Build and statically link the vendored GNU units C sources |
bindgen |
Regenerate FFI bindings from the C headers |
currency-update |
Enable Rust-native currency exchange rate updates |
License
Licensed under GPL-3.0-or-later. The vendored GNU units source code is also GPL-3.0-or-later.