Macro dimensioned::derived
[−]
[src]
macro_rules! derived { ($module:ident, $System:ident: $name:ident = $($tail:tt)*) => { ... }; }
Create a derived unit based on existing ones
This macro creates a type, so it is useful when you need to directly express the type of a derived unit that is not defined in its unit system.
If you need a variable of some derived unit, then the easiest way is to manipulate constants, like so:
use dim::si::M; let inverse_volume = 3.0 / M/M/M;
This macro is a bit fragile. It only supports the operators *
and /
and no parentheses. It
requires the base type of your unit system and the module it was defined in to be in scope.
Use it like so:
use dim::si::{self, SI}; derived!(si, SI: InverseMeter3 = Unitless / Meter3);
You may use any of the base or derived units that come with a unit system (but none created by this macro) on the right-hand side of the expression.
Example
#[macro_use] extern crate dimensioned as dim; use dim::si::{self, SI}; derived!(si, SI: InverseMeter3 = Unitless / Meter3); derived!(si, SI: Newton2PerSecond = Newton * Newton / Second); use dim::Recip; fn invert_volume(v: si::Meter3<f64>) -> InverseMeter3<f64> { v.recip() } fn main() { let v = 12.0 * si::M3; let inverse_volume = invert_volume(v); assert_eq!(1.0/v, inverse_volume); }