Skip to main content

Quantity

Trait Quantity 

Source
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§

Source

type UnitType: Unit<QuantityType = Self>

Associated type of unit

Required Methods§

Source

fn new(amount: AmountT, unit: Self::UnitType) -> Self

Returns a new instance of the type implementing Quantity.

Source

fn amount(&self) -> AmountT

Returns the amount of self.

Source

fn unit(&self) -> Self::UnitType

Returns the unit of self.

Provided Methods§

Source

fn iter_units() -> impl Iterator<Item = Self::UnitType>

Returns an iterator over the variants of Self::UnitType.

Source

fn unit_from_symbol(symbol: &str) -> Option<Self::UnitType>

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

Source

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

Return true if self and other have the same unit and their amounts are equal, otherwise false.

Source

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.

Source

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.

Source

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.

Source

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

Returns the quotient self / other, if both have the same unit.

§Panics

Panics if self and other have different units.

Source

fn fmt(&self, form: &mut Formatter<'_>) -> Result

Formats self using the given formatter.

§Errors

This function will only return an instance of Error returned from the formatter.

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§