HasRefUnit

Trait HasRefUnit 

Source
pub trait HasRefUnit:
    Quantity
    + Add<Self>
    + Sub<Self>
    + Div<Self>{
    const REF_UNIT: <Self as Quantity>::UnitType;

    // Provided methods
    fn unit_from_scale(amnt: AmountT) -> Option<Self::UnitType> { ... }
    fn equiv_amount(&self, unit: Self::UnitType) -> AmountT { ... }
    fn convert(&self, to_unit: Self::UnitType) -> Self { ... }
    fn eq(&self, other: &Self) -> bool { ... }
    fn partial_cmp(&self, other: &Self) -> Option<Ordering> { ... }
    fn add(self, rhs: Self) -> Self { ... }
    fn sub(self, rhs: Self) -> Self { ... }
    fn div(self, rhs: Self) -> AmountT { ... }
}
Expand description

Trait for quantities having a reference unit

Required Associated Constants§

Source

const REF_UNIT: <Self as Quantity>::UnitType

Unit used as reference for scaling the units of Self::UnitType.

Provided Methods§

Source

fn unit_from_scale(amnt: AmountT) -> Option<Self::UnitType>

Returns Some(unit) where unit.scale() == amnt, or None if there is no such unit.

Source

fn equiv_amount(&self, unit: Self::UnitType) -> AmountT

Returns factor so that factor * unit == self.

Source

fn convert(&self, to_unit: Self::UnitType) -> Self

Returns qty where qty == self and qty.unit() is to_unit.

Source

fn eq(&self, other: &Self) -> bool

Returns true, if self and other have equivalent amounts, otherwise false.

Source

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

Returns the partial order of selfs amount and others eqivalent amount in selfs unit.

Source

fn add(self, rhs: Self) -> Self

Returns the sum of self and other

Source

fn sub(self, rhs: Self) -> Self

Returns the difference between self and other

Source

fn div(self, rhs: Self) -> AmountT

Returns the quotient self / other

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 HasRefUnit for Acceleration

Source§

const REF_UNIT: AccelerationUnit = AccelerationUnit::MeterPerSecondSquared

Source§

impl HasRefUnit for Area

Source§

const REF_UNIT: AreaUnit = AreaUnit::SquareMeter

Source§

impl HasRefUnit for DataThroughput

Source§

const REF_UNIT: DataThroughputUnit = DataThroughputUnit::BytePerSecond

Source§

impl HasRefUnit for DataVolume

Source§

const REF_UNIT: DataVolumeUnit = DataVolumeUnit::Byte

Source§

impl HasRefUnit for Duration

Source§

const REF_UNIT: DurationUnit = DurationUnit::Second

Source§

impl HasRefUnit for Energy

Source§

const REF_UNIT: EnergyUnit = EnergyUnit::Joule

Source§

impl HasRefUnit for Force

Source§

const REF_UNIT: ForceUnit = ForceUnit::Newton

Source§

impl HasRefUnit for Frequency

Source§

const REF_UNIT: FrequencyUnit = FrequencyUnit::Hertz

Source§

impl HasRefUnit for Length

Source§

const REF_UNIT: LengthUnit = LengthUnit::Meter

Source§

impl HasRefUnit for Mass

Source§

const REF_UNIT: MassUnit = MassUnit::Kilogram

Source§

impl HasRefUnit for Power

Source§

const REF_UNIT: PowerUnit = PowerUnit::Watt

Source§

impl HasRefUnit for Speed

Source§

const REF_UNIT: SpeedUnit = SpeedUnit::MeterPerSecond

Source§

impl HasRefUnit for Volume

Source§

const REF_UNIT: VolumeUnit = VolumeUnit::CubicMeter

Source§

impl HasRefUnit for AmountT

Source§

const REF_UNIT: One = ONE