danwi 0.4.2

Zero-cost dimensional analysis library with SI units, compile-time checking, and no_std support
Documentation
use danwi::f64::{
    QuantityExt,
    constants::{V, W, mA, mV, mW},
    types::Volt,
};

fn adc_counts_to_voltage(count: u16) -> Volt {
    let v_ref = 3.3.V();
    v_ref * (count as f64 / 4096.0)
}

fn main() {
    let v = adc_counts_to_voltage(2048);
    println!("{:.3}", v.display_as(V)); // 1.650 V
    println!("{:.3}", v.display_as(mV)); // 1650.000 mV

    let shunt = 0.1.Ohm();
    let i = 50.0.mV() / shunt;
    println!("{:.3}", i.display_as(mA)); // 500.000 mA

    let dissipation = i * i * shunt;
    println!("{:.3}", dissipation.display_as(mW)); // 25.000 mW

    let p = 12.0.V() * 0.5.A();
    println!("{:.3}", p.display_as(W)); // 6.000 W

    let v_in = 5.0.V();
    let r_top = 2.2.kOhm();
    let r_bottom = 3.3.kOhm();
    let v_out = v_in * (r_bottom / (r_top + r_bottom));
    println!("{:.3}", v_out.display_as(V)); // 3.000 V
}