ucum-units 0.1.0

A total, conformance-tested implementation of UCUM (Unified Code for Units of Measure): parse, validate, analyze, compare and convert units.
Documentation
//! Prefix and atom tables, generated from the vendored `ucum-essence.xml` by
//! `build.rs`. The generated file (`$OUT_DIR/ucum_tables.rs`) is `include!`d at
//! the bottom of this module and references the types defined here.

// The generated table embeds faithful UCUM constants verbatim (e.g. the value
// of `[pi]`); these are data, not approximations to be replaced with std consts.
#![allow(clippy::approx_constant)]

/// How a unit atom's canonical value and dimension are obtained.
#[derive(Debug)]
pub(crate) enum AtomKind {
    /// A base unit: the value at the given index of the dimension vector is 1,
    /// the conversion factor is 1.
    Base(usize),
    /// A derived unit: `value` × (the canonical value of `unit`).
    Derived {
        /// Numeric multiplier.
        value: f64,
        /// UCUM reference-unit expression.
        unit: &'static str,
    },
    /// A special (non-multiplicative) unit defined by a named function applied
    /// to the proper unit `value` × `unit`.
    Special {
        /// UCUM special-function name (`Cel`, `degF`, `lg`, `ln`, `pH`, …).
        func: &'static str,
        /// Numeric multiplier of the proper unit.
        value: f64,
        /// UCUM proper-unit expression.
        unit: &'static str,
    },
}

/// A single unit-atom definition.
#[derive(Debug)]
pub(crate) struct AtomDef {
    /// The case-sensitive (`c/s`) UCUM code.
    pub code: &'static str,
    /// The case-insensitive (`c/i`) UCUM code (the upper-case `CODE` column).
    pub ci_code: &'static str,
    /// The printable English name (e.g. `meter`, `pascal`).
    pub name: &'static str,
    /// Whether a metric prefix may be attached.
    pub is_metric: bool,
    /// Whether this is an arbitrary unit (not commensurable with anything).
    pub is_arbitrary: bool,
    /// How to resolve the atom to a canonical value and dimension.
    pub kind: AtomKind,
}

/// A single prefix definition.
#[derive(Debug)]
pub(crate) struct PrefixDef {
    /// The case-sensitive (`c/s`) prefix code (e.g. `k`, `M`, `da`).
    pub code: &'static str,
    /// The case-insensitive (`c/i`) prefix code (the upper-case `CODE` column).
    pub ci_code: &'static str,
    /// The printable English name (e.g. `kilo`, `milli`).
    pub name: &'static str,
    /// The multiplicative factor (e.g. `1e3` for kilo).
    pub factor: f64,
}

include!(concat!(env!("OUT_DIR"), "/ucum_tables.rs"));