gnu-units-sys 2.27.0

Raw FFI bindings to the GNU units C library
Documentation
  • Coverage
  • 0.64%
    1 out of 156 items documented0 out of 25 items with examples
  • Size
  • Source code size: 1.02 MB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.28 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 8s Average build duration of successful builds.
  • all releases: 8s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • gabelluardo/gnu-units
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • gabelluardo

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-update feature)
  • Statically links vendored GNU units with no system dependencies

Usage

[dependencies]
gnu-units = "0.1"
use gnu_units::{convert, parse, conformable, Unit};

// Simple conversion factor
let factor = convert("km", "miles").unwrap();
assert!((factor - 0.62137).abs() < 1e-4);

// Conversion with a value
let km_val = 5.0;
let miles_val = km_val * convert("km", "miles").unwrap();

// Parse and inspect a unit
let unit = parse("kg m/s^2").unwrap();
println!("base units: {}", unit.base_units()); // "kg m / s s"

// Check conformability
let a = Unit::parse("km").unwrap();
let b = Unit::parse("miles").unwrap();
assert!(a.is_conformable(&b));

// Find all conformable units
let lengths = conformable("m").unwrap();
assert!(lengths.contains(&"mile".to_string()));

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.