pub trait Quantity:
Copy
+ Sized
+ Mul<AmountT> {
type UnitType: Unit<QuantityType = Self>;
// Required methods
fn new(amount: AmountT, unit: Self::UnitType) -> Self;
fn amount(&self) -> AmountT;
fn unit(&self) -> Self::UnitType;
// Provided methods
fn iter_units() -> impl Iterator<Item = Self::UnitType> { ... }
fn unit_from_symbol(symbol: &str) -> Option<Self::UnitType> { ... }
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 { ... }
fn fmt(&self, form: &mut Formatter<'_>) -> Result { ... }
}Expand description
The abstract type of quantities.
Required Associated Types§
Required Methods§
Provided Methods§
Sourcefn iter_units() -> impl Iterator<Item = Self::UnitType>
fn iter_units() -> impl Iterator<Item = Self::UnitType>
Returns an iterator over the variants of Self::UnitType.
Sourcefn unit_from_symbol(symbol: &str) -> Option<Self::UnitType>
fn unit_from_symbol(symbol: &str) -> Option<Self::UnitType>
Returns Some(unit) where unit.symbol() == symbol, or None if
there is no such unit.
Sourcefn eq(&self, other: &Self) -> bool
fn eq(&self, other: &Self) -> bool
Return true if self and other have the same unit and their
amounts are equal, otherwise false.
Sourcefn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
Returns the partial order of selfs and others amounts, if both
have the same unit, otherwise None.
Sourcefn add(self, rhs: Self) -> Self
fn add(self, rhs: Self) -> Self
Returns the sum of self and other, if both have the same unit.
§Panics
Panics if self and other have different units.
Sourcefn sub(self, rhs: Self) -> Self
fn sub(self, rhs: Self) -> Self
Returns the difference between self and other, if both have the
same unit.
§Panics
Panics if self and other have different units.
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.