Skip to main content

Unit

Trait Unit 

Source
pub trait Unit:
    Copy
    + Eq
    + PartialEq
    + Sized
    + Mul<AmountT>
    + Display {
    type QuantityType: Quantity<UnitType = Self>;

    // Required methods
    fn iter() -> impl Iterator<Item = Self>;
    fn name(&self) -> String;
    fn symbol(&self) -> String;
    fn si_prefix(&self) -> Option<SIPrefix>;

    // Provided methods
    fn from_symbol(symbol: &str) -> Option<Self> { ... }
    fn as_qty(&self) -> Self::QuantityType { ... }
    fn fmt(&self, form: &mut Formatter<'_>) -> Result { ... }
}
Expand description

The abstract type of units used to define quantities.

Required Associated Types§

Source

type QuantityType: Quantity<UnitType = Self>

Associated type of quantity

Required Methods§

Source

fn iter() -> impl Iterator<Item = Self>

Returns an iterator over the variants of Self.

Source

fn name(&self) -> String

Returns the name of self.

Source

fn symbol(&self) -> String

Returns the symbol used to represent self.

Source

fn si_prefix(&self) -> Option<SIPrefix>

Returns the SI prefix of self, or None is self is not a SI unit.

Provided Methods§

Source

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

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

Source

fn as_qty(&self) -> Self::QuantityType

Returns 1 * self

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".

Implementors§