Trait Unit

Source
pub trait Unit {
    type Dimension;

    // Required method
    fn parameters() -> UnitParameters;

    // Provided methods
    fn to<S: Unit<Dimension = Self::Dimension>, E: TensorElement>(value: E) -> E { ... }
    fn from<S: Unit<Dimension = Self::Dimension>, E: TensorElement>(
        value: E,
    ) -> E { ... }
    fn to_base(value: c64) -> c64 { ... }
    fn from_base(value: c64) -> c64 { ... }
    fn symbol() -> &'static str { ... }
    fn name() -> &'static str { ... }
    fn ratio<T: Unit<Dimension = Self::Dimension>>() -> f64 { ... }
}

Required Associated Types§

Required Methods§

Provided Methods§

Source

fn to<S: Unit<Dimension = Self::Dimension>, E: TensorElement>(value: E) -> E

Source

fn from<S: Unit<Dimension = Self::Dimension>, E: TensorElement>(value: E) -> E

Source

fn to_base(value: c64) -> c64

Source

fn from_base(value: c64) -> c64

Source

fn symbol() -> &'static str

Source

fn name() -> &'static str

Source

fn ratio<T: Unit<Dimension = Self::Dimension>>() -> f64

Returns the conversion ratio from the current unit into unit T.

The ratio is computed as:

self.scale / T::parameters().scale

This function assumes that both units share the same Dimension.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl Unit for Ampere

Source§

type Dimension = Dimension<0, 0, 0, 0, 1>

Source§

impl Unit for Atmosphere

Source§

type Dimension = Dimension<-1, 1, -2>

Source§

impl Unit for Bar

Source§

type Dimension = Dimension<-1, 1, -2>

Source§

impl Unit for Candela

Source§

type Dimension = Dimension<0, 0, 0, 0, 0, 0, 1>

Source§

impl Unit for Celsius

Source§

type Dimension = Dimension<0, 0, 0, 1>

Source§

impl Unit for Centimeter

Source§

impl Unit for Century

Source§

impl Unit for CubicMeter

Source§

impl Unit for Dalton

Source§

impl Unit for Day

Source§

impl Unit for ElectronVolt

Source§

type Dimension = Dimension<2, 1, -2>

Source§

impl Unit for Fahrenheit

Source§

type Dimension = Dimension<0, 0, 0, 1>

Source§

impl Unit for Gallon

Source§

impl Unit for Gram

Source§

impl Unit for Hertz

Source§

type Dimension = Dimension<0, 0, -1>

Source§

impl Unit for Horsepower

Source§

type Dimension = Dimension<2, 1, -3>

Source§

impl Unit for Hour

Source§

impl Unit for Joule

Source§

type Dimension = Dimension<2, 1, -2>

Source§

impl Unit for Kelvin

Source§

type Dimension = Dimension<0, 0, 0, 1>

Source§

impl Unit for Kilogram

Source§

impl Unit for Kilometer

Source§

impl Unit for KilometersPerHour

Source§

type Dimension = Dimension<1, 0, -1>

Source§

impl Unit for Lbf

Source§

type Dimension = Dimension<1, 1, -2>

Source§

impl Unit for LightYear

Source§

impl Unit for Liter

Source§

impl Unit for Meter

Source§

impl Unit for MetersPerSecond

Source§

type Dimension = Dimension<1, 0, -1>

Source§

impl Unit for MetersPerSecondSquared

Source§

type Dimension = Dimension<1, 0, -2>

Source§

impl Unit for Micrometer

Source§

impl Unit for Microsecond

Source§

impl Unit for Milliliter

Source§

impl Unit for Millimeter

Source§

impl Unit for Millisecond

Source§

impl Unit for Minute

Source§

impl Unit for Mole

Source§

type Dimension = Dimension<0, 0, 0, 0, 0, 1>

Source§

impl Unit for Nanosecond

Source§

impl Unit for Newton

Source§

type Dimension = Dimension<1, 1, -2>

Source§

impl Unit for Pascal

Source§

type Dimension = Dimension<-1, 1, -2>

Source§

impl Unit for PlankLength

Source§

impl Unit for Pound

Source§

impl Unit for Second

Source§

impl Unit for SquareMeter

Source§

impl Unit for Watt

Source§

type Dimension = Dimension<2, 1, -3>

Source§

impl Unit for Year

Source§

impl Unit for Ångström

Source§

impl Unit for Unitless

Source§

impl<L: Unit, R: Unit> Unit for UnitMul<L, R>

Source§

impl<T: Unit> Unit for UnitInv<T>