dimensioned::make_units!
[−]
[src]
macro_rules! make_units { ($System:ident, $Unitless:ident, $one:ident; base { $($Type:ident, $constant:ident, $print_as:ident;)+ } derived { $($derived_constant:ident: $Derived:ident = $e:expr;)* } ) => ( make_units_adv!{ $System, $Unitless, $one, f64, 1.0; base { $(P1, $Type, $constant, $print_as;)* } derived { $($derived_constant: $Derived = $e;)* } } ); }
Create a unit system.
As this macro performs various imports, it is strongly recommended that you call it inside of its own module.
Example
#[macro_use] extern crate dimensioned; mod fruit { make_units! { Fruit, Unitless, one; base { Apple, apple, a; Banana, banana, b; Cucumber, cuke, c; Mango, mango, m; Watermelon, watermelon, w; } derived { } } } use fruit::{apple, banana, cuke, mango, watermelon}; fn main() { let fruit_salad = apple * banana * mango * mango * watermelon; println!("Mmmm, delicious: {}", fruit_salad); assert_eq!(format!("{}", fruit_salad), "1 a*b*m^2*w"); }
The line Fruit, Unitless, one; names the unit system Fruit, names its type for
unitless data Unitless and creates the corresponding constant one.
The base block is used to define the base units of this system. The line Apple, apple, a; creates the unit Apple, the corresponding constant apple, and will use
the token "a" to print Apples.
The derived block is not yet implemented, but will be used to define derived units and
constants.