measurements
A Rust library for type-safe physical measurements, units, SI prefixes, and ranges.
Features
- Type-safe measurements with units and SI prefixes
- One- and two-dimensional arrays of measurements (
M1d,M2d) - Range types for measurements with min, max, and step (
RangedMeasurement) - Percentage type for expressing proportions
- Prefix arithmetic and conversions
- Custom derive macro for units of measurement (
Uom) - Serde support for serialization/deserialization
- Parallel operations on arrays (with
ndarray+rayon)
Example
use *;
let voltage = new; // 5 mV
let current = new; // 2 A
let arr = new;
println!;
Units
- Volt (
Volt) - Ampere (
Ampere) - Watt (
Watt) - Second (
Second) - Hertz (
Hertz) - (Easily extensible via the
Uomtrait and derive macro)
Prefixes
Supports SI prefixes: Tera, Giga, Mega, Kilo, None, Milli, Micro, Nano, Femto.
Ranges
let range = new;
assert!;
Percentage
let p = percentage!;
assert_eq!;
Crate Structure
measurement.rs— Scalar measurementsm1d.rs,m2d.rs— 1D and 2D arrays of measurementsranged_measurement.rs— Ranges for measurementspercentage.rs— Percentage type and macroprefix.rs— SI prefix enum and arithmeticuom.rs— Units of measurement trait and typesprelude.rs— Convenient re-exports
Usage
Add to your Cargo.toml:
[]
= { = "." }
= { = "0.15", = ["serde", "rayon"] }
= { = "1.0", = ["derive"] }
License
MIT
See the documentation for more details and examples.