danwi
A zero-cost dimensional analysis library for Rust with SI units, compile-time
type checking, and no_std support.
Usage
use *;
// dimensions combine at the type level; mismatches are compile errors
let v = 5.0.mA * 2.0.kOhm;
assert_eq!;
// convert and format in any unit of the same dimension
assert_eq!;
println!; // 10000 mV
// values are stored in SI base units, so mixed prefixes just work
let len = 100.0.m + 50.0 * cm + 0.001 * km;
assert_eq!;
// non-SI units: minute, hour, Celsius, litre, inch, ...
let temp = 25.0.celsius;
assert_eq!;
println!; // 25 °C
Custom units are one line each; the built-in set is itself a single
units! invocation:
use *;
use F64QuantityExt as _;
assert_eq!;
Construction and conversion compile to at most one float op each, and
everything in between is plain scalar arithmetic; verify with
cargo rustc --release --example asm_check -- --emit=asm.