uom

Units of measurement is a crate that does automatic type-safe zero-cost dimensional analysis. You can create your own systems or use the pre-built International System of Units (SI) which is based on the International System of Quantities (ISQ) and includes numerous quantities (length, mass, time, ...) with conversion factors for even more numerous measurement units (meter, kilometer, foot, mile, ...). No more crashing your climate orbiter!

Documentation

Usage

Add this to your Cargo.toml:

toml [dependencies] uom = "0.11.0"

and this to your crate root:

rust extern crate uom;

The simple example below shows how to use quantities and units as well as how uom stops invalid operations.

```rust extern crate uom;

use uom::si::f32::*; use uom::si::length::kilometer; use uom::si::time::second;

fn main() { let length = Length::new(5.0, kilometer); let time = Time::new(15.0, second); let velocity = length / time; //let error = length + time; // error[E0308]: mismatched types } ```

See the examples directory for more advanced usage:

Design

Rather than working with measurement units (meter, kilometer, foot, mile, ...) uom works with quantities (length, mass, time, ...). This simplifies usage because units are only involved at interface boundaries: the rest of your code only needs to be concerned about the quantities involved. This also makes operations on quantities (+, -, *, /, ...) have zero runtime cost1 over using the raw storage type (e.g. f32).

uom normalizes values to the base unit for the quantity. Alternative base units can be used by executing the macro defined for the system of quantities (ISQ! for the SI). uom supports both f32 and f64 as the underlying storage type.

  1. Once codegen bug #38269 is resolved.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.