Trait uom::Conversion
source · pub trait Conversion<V> {
type T: ConversionFactor<V>;
// Provided methods
fn coefficient() -> Self::T { ... }
fn constant(op: ConstantOp) -> Self::T { ... }
fn conversion(&self) -> Self::T
where Self: Sized { ... }
}
Expand description
Trait to identify units which have a conversion factor.
§Generic Parameters
V
: Underlying storage type trait is implemented for.
Required Associated Types§
sourcetype T: ConversionFactor<V>
type T: ConversionFactor<V>
Conversion factor type specific to the underlying storage type.
Provided Methods§
sourcefn coefficient() -> Self::T
fn coefficient() -> Self::T
Coefficient portion of conversion factor for
converting the given unit. To convert to the base unit for the quantity use (value + constant()) * coefficient()
. To convert from the base unit, (value / coefficient()) - constant()
is used. Implementation should return the multiplicative identity
(Self::T::one()
) if no coefficient exists.
sourcefn constant(op: ConstantOp) -> Self::T
fn constant(op: ConstantOp) -> Self::T
Constant portion of conversion factor for
converting the given unit. To convert to the base unit for the quantity use (value + constant()) * coefficient()
. To convert from the base unit, (value / coefficient()) - constant()
is used. Implementation should return the additive identity (Self::T::zero()
)
if no constant exists. See ConstantOp
documentation for details about parameter use to
ensure the method optimizes correctly.
sourcefn conversion(&self) -> Self::Twhere
Self: Sized,
fn conversion(&self) -> Self::Twhere
Self: Sized,
Instance conversion factor.
Default implementation returns the coefficient: Self::coefficient()
.