[][src]Macro uom::quantity

macro_rules! quantity {
    (
        $(#[$quantity_attr:meta])* quantity: $quantity:ident; $description:expr;
        $(#[$dim_attr:meta])* dimension: $system:ident<$($dimension:ident),+>;
        units {
            $($(#[$unit_attr:meta])* @$unit:ident: $($conversion:expr),+;
                $abbreviation:expr, $singular:expr, $plural:expr;)+
        }
    ) => { ... };
    (
        $(#[$quantity_attr:meta])* quantity: $quantity:ident; $description:expr;
        $(#[$dim_attr:meta])* dimension: $system:ident<$($dimension:ident),+>;
        kind: $kind:ty;
        units {
            $($(#[$unit_attr:meta])* @$unit:ident: $($conversion:expr),+; $abbreviation:expr,
                $singular:expr, $plural:expr;)+
        }
    ) => { ... };
    (@unit $(#[$unit_attr:meta])+ @$unit:ident) => { ... };
    (@unit @$unit:ident) => { ... };
    (@coefficient $factor:expr, $const:expr) => { ... };
    (@coefficient $factor:expr) => { ... };
    (@constant $op:ident $factor:expr, $const:expr) => { ... };
    (@constant $op:ident $factor:expr) => { ... };
}

Macro to implement a quantity and associated measurement units. Note that this macro must be executed in direct submodules of the module where the system! macro was executed. @... match arms are considered private.

  • $quantity_attr: Quantity attributes. Generally used to set documentation comments for the quantity.
  • $quantity: Quantity name (e.g. Length).
  • $description: Quantity description (e.g. "length").
  • $dim_attr: Dimension attributes. Generally used to set documentation comments for the quantity's dimension type alias.
  • $system: System of quantities type (e.g. ISQ).
  • $dimension: Power of a factor for each base quantity in the system. Power should be represented as a typenum type-level integer (e.g. N1, Z0, P1, P2, ...).
  • $kind: Kind of the quantity. Optional. This variable should only be specified when defining a quantity that has the same dimensions as another quantity but isn't comparable. When not specified uom::Kind is used.
  • $unit: Unit name (e.g. meter, foot).
  • $conversion: Conversion (coefficient and constant factor) from the unit to the base unit of the quantity (e.g. 3.048_E-1 to convert foot to meter. 1.0_E0, 273.15_E0 to convert celsius to kelvin.). The coefficient is required and the constant factor is optional. Note that using a unit with a non-zero constant factor is not currently supported as a base unit.
  • $abbreviation: Unit abbreviation (e.g. "m").
  • $singular: Singular unit description (e.g. "meter").
  • $plural: Plural unit description (e.g. "meters").

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

#[macro_use]
extern crate uom;

#[macro_use]
mod length {
    quantity! {
        /// Length (base unit meter, m<sup>1</sup>).
        quantity: Length; "length";
        /// Length dimension, m<sup>1</sup>.
        dimension: Q<P1 /*length*/, Z0 /*mass*/, Z0 /*time*/>;
        units {
            @meter: 1.0E0; "m", "meter", "meters";
            @foot: 3.048E-1; "ft", "foot", "feet";
        }
    }
}