danwi 0.4.2

Zero-cost dimensional analysis library with SI units, compile-time checking, and no_std support
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use danwi::{Quantity, dimension::Energy, kind::Torque, prelude::*};

type TorqueQ = Quantity<f64, Energy, Torque>;

fn main() {
    let wrench: TorqueQ = (50.0.N() * 0.4.m()).cast_kind();
    let spec: TorqueQ = (25.0.J()).cast_kind();

    assert!(wrench < spec);
    println!("applied: {} N·m of {} N·m", wrench.value(), spec.value());

    // wrench + 5.0.J() would not compile: same dimension, different kind

    let work_per_radian = wrench.erase_kind();
    assert_eq!(work_per_radian, 20.0.J());
    println!("as energy: {}", work_per_radian.display_as(J)); // as energy: 20 J
}