uy
Compile-time unit safety for Rust. Catches unit errors at compile time with zero runtime cost.
See docs.rs/uy for the full API.
use ;
let distance: = new;
let time: = new;
let speed: = distance / time;
// This won't compile - can't add meters to seconds:
// let wrong = distance + time;
Installation
[]
= "0.3"
Usage
Basic quantities
use ;
let mass: = new;
let force: = new;
Unit algebra
Units combine through multiplication and division. All derived and compound units are just type aliases to combinations of Mul, Div, and base units:
use ;
// These are equivalent:
let v1: = new;
let v2: = new;
// Unit algebra works automatically:
let length: = new;
let width: = new;
let area: = length * width; // m * m = m²
Prefix conversions
Scale is encoded in the type via TenTo<N>. Prefixes like milli and kilo are type aliases:
use ;
// si::milli<U> is just Mul<U, TenTo<-3>>
let meters: = new;
let millimeters: = meters.convert;
assert_eq!;
Accessing values
Quantity implements Deref, so use * to get the inner value:
use ;
let temp: = new;
println!;
no_std Support
This library supports compiling in no_std environments with nightly rust using the
core_float_math feature. This feature is required to perform powi operations without
std.
To use this library without std, disable the default-features when depending on it. The
std feature is enabled by default, which disables no_std support.
License
MIT