Skip to main content

ConversionTable

Struct ConversionTable 

Source
pub struct ConversionTable<Q: Quantity, const N: usize> {
    pub mappings: [(Q::UnitType, Q::UnitType, AmountT, AmountT); N],
}
Expand description

A table defining the conversion between instances of quantity Q having different units.

Each entry of the table is holding the following elements:

  • from_unit: Q::UnitType,
  • to_unit: Q::UnitType,
  • factor: AmountT,
  • offset: AmountT

defining the conversion to_amount = from_amount * factor + offset

Fields§

§mappings: [(Q::UnitType, Q::UnitType, AmountT, AmountT); N]

Table of tuples (from_unit, to_unit, factor, offset), defining the conversion to_amount = from_amount * factor + offset

Trait Implementations§

Source§

impl<Q: Quantity, const N: usize> Converter<Q> for ConversionTable<Q, N>

Source§

fn convert(self, qty: &Q, to_unit: Q::UnitType) -> Option<Q>

Returns conv where conv ≣ qty and conv.unit() is to_unit, or None if conversion is not possible.
Source§

impl<Q: Debug + Quantity, const N: usize> Debug for ConversionTable<Q, N>
where Q::UnitType: Debug,

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<Q, const N: usize> Freeze for ConversionTable<Q, N>
where [(<Q as Quantity>::UnitType, <Q as Quantity>::UnitType, f64, f64); N]: Freeze,

§

impl<Q, const N: usize> RefUnwindSafe for ConversionTable<Q, N>
where [(<Q as Quantity>::UnitType, <Q as Quantity>::UnitType, f64, f64); N]: RefUnwindSafe,

§

impl<Q, const N: usize> Send for ConversionTable<Q, N>
where [(<Q as Quantity>::UnitType, <Q as Quantity>::UnitType, f64, f64); N]: Send,

§

impl<Q, const N: usize> Sync for ConversionTable<Q, N>
where [(<Q as Quantity>::UnitType, <Q as Quantity>::UnitType, f64, f64); N]: Sync,

§

impl<Q, const N: usize> Unpin for ConversionTable<Q, N>
where [(<Q as Quantity>::UnitType, <Q as Quantity>::UnitType, f64, f64); N]: Unpin,

§

impl<Q, const N: usize> UnsafeUnpin for ConversionTable<Q, N>
where [(<Q as Quantity>::UnitType, <Q as Quantity>::UnitType, f64, f64); N]: UnsafeUnpin,

§

impl<Q, const N: usize> UnwindSafe for ConversionTable<Q, N>
where [(<Q as Quantity>::UnitType, <Q as Quantity>::UnitType, f64, f64); N]: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.