packages

units::unit::catalogue

The unit catalogue: SI base and derived units, units accepted with the SI, and common other units with their NIST SP 811 factors (exact where the definition is exact). Parsing and the error suggestions read it.

Structs

EntrySource

pub struct Entry

One unit of the catalogue.

nabi
let ft = units::unit::catalogue::find("ft") ?? panic("ft");
assert(ft.scale == 0.3048 && ft.name == "foot");
  • pub symbol: str§

    Source

    The symbol ("ft").

  • pub name: str§

    Source

    The singular name ("foot").

  • pub plural: str§

    Source

    The plural name ("feet").

  • pub scale: f64§

    Source

    One of the unit in coherent SI units.

  • pub offset: f64§

    Source

    The SI value of zero of the unit (temperature scales only).

  • pub dim: Dim§

    Source

    The dimension.

  • pub prefixes: bool§

    Source

    Whether SI prefixes apply (km, kilometre).

Functions

entriesSource

pub fn entries() -> List<Entry>

Every unit of the catalogue, without prefixed forms.

nabi
let all = units::unit::catalogue::entries();
assert(all.iter().any(|e: units::unit::catalogue::Entry| e.symbol == "psi"));

findSource

pub fn find(text: str) -> Entry | none

The catalogue unit written text: its symbol ("ft"), its name or plural ("foot", "feet", any case), or a common other spelling ("meter", "°C", "in"). No prefixes; DynUnit::parse adds them.

nabi
use units::unit::catalogue::find;

assert((find("Feet") ?? panic("feet")).symbol == "ft");
assert((find("°C") ?? panic("degC")).offset == 273.15);
assert((find("Degrees Fahrenheit") ?? panic("degF")).symbol == "degF");
assert(find("km") == none);