Trait dimensioned::traits::Map [] [src]

pub trait Map<ValueOut>: Dimensionless {
    type Output;
    fn map<F: FnOnce(Self::Value) -> ValueOut>(self, f: F) -> Self::Output;
}

Perform an operation on the contained value.

This trait is only defined for unitless types, and it keeps them unitless, so it is perfectly safe to use.

It can be used similarly to MapUnsafe, but only for Dimensionless quantities, and it cannot make them non-Dimensionless.

Example

extern crate dimensioned as dim;

fn main() {
    use dim::si;
    let x1 = 2.0 * si::ONE;
    let x2 = 2.0f64;

    use dim::Map;
    assert_eq!(x1.map(|v| v.sin()), x2.sin() * si::ONE);
}

Associated Types

The type to which the input is mapped

Required Methods

Perform the map

Implementors