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§
Provided Methods§
Sourcefn unit_from_scale(amnt: AmountT) -> Option<Self::UnitType>
fn unit_from_scale(amnt: AmountT) -> Option<Self::UnitType>
Returns Some(unit)
where unit.scale()
== amnt
, or None
if
there is no such unit.
Sourcefn equiv_amount(&self, unit: Self::UnitType) -> AmountT
fn equiv_amount(&self, unit: Self::UnitType) -> AmountT
Returns factor
so that factor
* unit
== self
.
Sourcefn convert(&self, to_unit: Self::UnitType) -> Self
fn convert(&self, to_unit: Self::UnitType) -> Self
Returns qty
where qty
== self
and qty.unit()
is to_unit
.
Sourcefn eq(&self, other: &Self) -> bool
fn eq(&self, other: &Self) -> bool
Returns true, if self
and other
have equivalent amounts, otherwise
false
.
Sourcefn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
Returns the partial order of self
s amount and other
s eqivalent
amount in self
s unit.
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.