danwi 0.4.2

Zero-cost dimensional analysis library with SI units, compile-time checking, and no_std support
Documentation
//! The built-in unit set: SI base and derived units, plus a few common
//! non-SI units (minute, hour, Celsius, litre, inch, bar).
//!
//! One [`units!`](crate::units) invocation; adding a unit is one line.
//! The SI base unit of mass is the kilogram: `gram` is declared with
//! `scale: 1/1000` so that `kg` is the coherent unit newton, joule, etc.
//! are defined against.

use crate::dimension::*;

crate::units! {
    // SI base units
    /// Time (SI base unit).
    second: Time { symbol: s, prefixes: all },
    /// Length (SI base unit).
    meter: Length { symbol: m, prefixes: all },
    /// Mass. The SI base unit is the kilogram; the gram scales by 1/1000.
    gram: Mass { symbol: g, scale: 1 / 1_000, prefixes: all },
    /// Electric current (SI base unit).
    ampere: ElectricCurrent { symbol: A, prefixes: all },
    /// Thermodynamic temperature (SI base unit).
    kelvin: ThermodynamicTemperature { symbol: K, prefixes: all },
    /// Amount of substance (SI base unit).
    mole: AmountOfSubstance { symbol: mol, prefixes: all },
    /// Luminous intensity (SI base unit).
    candela: LuminousIntensity { symbol: cd, prefixes: all },

    // Kinematic
    /// Frequency.
    hertz: Frequency { symbol: Hz, prefixes: all },
    /// Velocity.
    meter_per_second: Velocity { symbol: mps, display: "m/s", prefixes: all },
    /// Acceleration.
    meter_per_second_squared: Acceleration { symbol: mps2, display: "m/s²", prefixes: all },

    // Mechanical
    /// Force.
    newton: Force { symbol: N, prefixes: all },
    /// Energy, work, heat.
    joule: Energy { symbol: J, prefixes: all },
    /// Power.
    watt: Power { symbol: W, prefixes: all },
    /// Pressure.
    pascal: Pressure { symbol: Pa, prefixes: all },

    // Electrical and magnetic
    /// Electric potential difference.
    volt: Voltage { symbol: V, prefixes: all },
    /// Electrical resistance.
    ohm: Resistance { symbol: Ohm, display: "Ω", prefixes: all },
    /// Electrical conductance.
    siemens: Conductance { symbol: S, prefixes: all },
    /// Electric charge.
    coulomb: ElectricCharge { symbol: C, prefixes: all },
    /// Capacitance.
    farad: Capacitance { symbol: F, prefixes: all },
    /// Inductance.
    henry: Inductance { symbol: H, prefixes: all },
    /// Magnetic flux density.
    tesla: MagneticFluxDensity { symbol: T, prefixes: all },
    /// Magnetic flux.
    weber: MagneticFlux { symbol: Wb, prefixes: all },

    // Common non-SI units
    /// 60 seconds.
    minute: Time { symbol: min, scale: 60 },
    /// 3600 seconds.
    hour: Time { symbol: h, scale: 3_600 },
    /// Temperature with a 273.15 K offset. Beware that quantities are
    /// stored in kelvin: constructing and reading apply the offset, so a
    /// temperature *difference* read via `to(degC)` is off by 273.15.
    celsius: ThermodynamicTemperature { symbol: degC, display: "°C", offset: 27_315 / 100 },
    /// 10⁻³ m³.
    liter: Volume { symbol: L, scale: 1 / 1_000, prefixes: all },
    /// Exactly 25.4 mm.
    inch: Length { symbol: inch, display: "in", scale: 254 / 10_000 },
    /// 100 000 Pa.
    bar: Pressure { symbol: bar, scale: 100_000 },
}