packages

units::ops

On this page

Operators for unit code (feature ops, on by default):

q → u the quantity expressed in unit u (level of |) x° degrees as an angle in radians (postfix, level of ?) √q square root of a quantity (core's √, always on)

Each also has a named form: q.to(u), deg.of(x), q.sqrt().

Traits

ConvertSource

pub trait Convert<Rhs>

q → u: the quantity in unit u, for printing (3km → mi prints 1.8641135767120018 mi). Binds like |: looser than arithmetic, tighter than comparison, so a + b → km converts the sum. Static quantities take static units and the types check the dimension; a Measure takes a DynUnit and gives a Result.

nabi
use units::symbols::{degF, h, km, m, mi, s};

assert((5km → mi).unit.symbol == "mi");
assert((1km + 500m → m).value == 1500.0);
assert((36km / 1h → m / s).value == 10.0);
assert((20degC → degF).value == 68.0);

DegreesSource

pub trait Degrees

x°: x degrees as an angle, a dimensionless quantity in radians (90° is pi/2). Binds like postfix ?, so -30° is -(30°) and (a + b)° takes the sum.

nabi
use units::ops::Degrees;

assert((180°).value == f64::PI);
assert((90°).sin() == 1.0);