macro_rules! system {
($(#[$quantities_attr : meta]) * quantities : $quantities : ident
{
$($(#[$name_attr : meta]) * $name : ident : $unit : ident, $symbol :
ident ;) +
} $(#[$units_attr : meta]) * units : $units : ident
{ $($module : ident :: $quantity : ident,) + }) => { ... };
($(#[$quantities_attr : meta]) * quantities : $quantities : ident
{
$($(#[$name_attr : meta]) * $name : ident : $unit : ident, $symbol :
ident ;) +
} $(#[$units_attr : meta]) * units : $units : ident
{ $(mod $module : ident :: $quantity : ident,) + }) => { ... };
(@ quantities $path : path, $V : ty ; $($name : ident), + ; ($($U : ident), +)
; $($module : ident :: $quantity : ident), +) => { ... };
(@ replace $_t : tt $sub : ty) => { ... };
}
Expand description
Macro to implement a system of quantities. @...
match
arms are considered private.
$quantities_attr
: System of quantities attributes. Generally used to set documentation comments for the system of quantities.$quantities
: Name of the system of quantities (e.g.ISQ
).$name_attr
: Base quantity attributes. Generally used to set documentation comments for base units.$name
: Name of the base quantities for the system of quantities (e.g.length
,mass
, …). Note that this name must match the module name of the quantity.$unit
: Base unit of the quantity (e.g.meter
,kilogram
).$symbol
: Dimension symbol of the quantity.$units_attr
: System of units attributes. Generally used to set documentation comments for the system of units.$units
: Name of the system of units (e.g.SI
).$module
: Module name of the quantity. When prefixed by themod
keyword the module must already be defined with the#[macro_use]
attribute. A#[macro_use] pub mod $module;
statement is generated if this variable is not prefixed by themod
keyword.$quantity
: Quantity name (e.g.Length
,Mass
, …).
An example invocation is given below for a meter-kilogram-second system. The #[macro_use]
attribute must be used when including the uom
crate to make the system!
macro available.
#[macro_use]
extern crate uom;
system! {
/// System of quantities, Q.
quantities: Q {
length: meter, L;
mass: kilogram, M;
time: second, T;
}
/// System of units, U.
units: U {
mod length::Length,
mod mass::Mass,
mod time::Time,
}
}