[][src]Macro uom::unit

macro_rules! unit {
    (
        system: $system:path;
        quantity: $quantity:path;

        $($(#[$unit_attr:meta])* @$unit:ident: $($conversion:expr),+;
            $abbreviation:expr, $singular:expr, $plural:expr;)+
    ) => { ... };
    (
        @units $($(#[$unit_attr:meta])* @$unit:ident: $($conversion:expr),+;
            $abbreviation:expr, $singular:expr, $plural:expr;)+
    ) => { ... };
    (@unit $(#[$unit_attr:meta])+ @$unit:ident $plural:expr) => { ... };
    (@unit @$unit:ident $plural:expr) => { ... };
    (@coefficient $factor:expr, $const:expr) => { ... };
    (@coefficient $factor:expr) => { ... };
    (@constant $op:ident $factor:expr, $const:expr) => { ... };
    (@constant $op:ident $factor:expr) => { ... };
}

Macro to implement a set of measurement units. Note that units manually defined using this macro will not be included in the quantity unit enum or associated functions, or in the FromStr implementation. Using this macro will create submodules for the underlying storage types that are enabled (e.g. mod f32). @... match arms are considered private.

When using the pre-built SI system included with uom this macro allows for new units to quickly be defined without requiring a release. Pull requests to add new units upstream area always greatly appreciated.

An example invocation is given below to add kilometers to length in a meter-kilogram-second system. The #[macro_use] attribute must be used when including the uom crate to make the unit! macro available.

#[macro_use]
extern crate uom;

unit! {
    system: crate::mks;
    quantity: crate::mks::length;

    @kilometer: 1.0E-03; "km", "kilometer", "kilometers";
}