Macro uom::quantity [] [src]

macro_rules! quantity {
    (
        $(#[$quantity_attr:meta])* quantity: $quantity:ident;
        $(#[$dim_attr:meta])* dimension: $system:ident<$($dimension:ident),+>;
        units {
            $($unit:ident: $conversion: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.

  • $quantity_attr: Quantity attributes. Generally used to set documentation comments for the quantity.
  • $quantity: Quantity name (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, ...).
  • $unit: Unit name (e.g. meter, foot).
  • $conversion: Conversion from the unit to the base unit of the quantity (e.g. 3.048E-1 to convert foot to meter).

An example invocation is given below for the quantity of length in a meter-kilogram-second system.

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