Skip to main content

Mass

Enum Mass 

Source
#[non_exhaustive]
pub enum Mass { ShortTon, LongTon, Pound, Ounce, Tonne, Kilogram, Gram, Centigram, Milligram, Microgram, AtomicMassUnit, }
Expand description

A unit of mass.

The listed abbreviations are the abbreviations used to parse the unit with FromStr. The main abbreviation comes first, followed by any alternate abbreviations that can be used.

The conversions are listed in terms of the base unit. The base unit for Mass is Mass::Kilogram.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

ShortTon

A US (short) ton (2000 pounds).

  • Abbreviation: tn

  • 1 tn = 907.18474 kg

§

LongTon

An imperial (long) ton (2240 pounds).

  • Abbreviation: lt

  • 1 lt = 1016.0469088 kg

§

Pound

  • Abbreviation: lb

  • 1 lb = 0.45359237 kg

§

Ounce

  • Abbreviation: oz

  • 1 oz = 0.028349523125 kg

§

Tonne

A metric tonne (1000 kilograms).

  • Abbreviation: t

  • 1 t = 1000.0 kg

§

Kilogram

  • Abbreviation: kg

  • 1 kg = 1.0 kg

§

Gram

  • Abbreviation: g

  • 1 g = 0.001 kg

§

Centigram

  • Abbreviation: cg

  • 1 cg = 1e-5 kg

§

Milligram

  • Abbreviation: mg

  • 1 mg = 1e-6 kg

§

Microgram

  • Abbreviation: µg, ug

  • 1 µg = 1e-9 kg

§

AtomicMassUnit

An atomic mass unit (1/12 of the mass of a carbon 12 atom).

  • Abbreviation: amu

  • 1 amu = 1.66053906892e-27 kg

Implementations§

Source§

impl Mass

Source

pub fn pow(&self, power: i8) -> Unit

Creates a Unit with this quantity type and specified power.

Source

pub fn squared(&self) -> Unit

Creates a Unit with this quantity type and power 2.

Source

pub fn cubed(&self) -> Unit

Creates a Unit with this quantity type and power 3.

Trait Implementations§

Source§

impl Clone for Mass

Source§

fn clone(&self) -> Mass

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Convert for Mass

Source§

const BASE: Self = Mass::Kilogram

The base unit of this unit. Read more
Source§

fn conversion_factor(&self) -> f64

Returns the conversion factor from &self to Convert::BASE, i.e. the value to multiply a quantity in this unit by, in order to get a quantity in Convert::BASE. If the self unit is the same as this unit, then this function should return 1.0. Read more
Source§

fn conversion_factor_to(&self, _: impl Into<Unit>) -> Option<f64>

Defines the conversion factor from Convert::BASE, to a base unit that Convert::BASE is derived from. Returns None if there is no conversion factor, meaning the two units are unrelated. Read more
Source§

impl Copy for Mass

Source§

impl Debug for Mass

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Display for Mass

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Eq for Mass

Source§

impl From<Mass> for CompoundUnit

Source§

fn from(u: Mass) -> Self

Converts to this type from the input type.
Source§

impl From<Mass> for Unit

Source§

fn from(u: Mass) -> Self

Converts to this type from the input type.
Source§

impl From<Mass> for Base

Source§

fn from(u: Mass) -> Self

Converts to this type from the input type.
Source§

impl FromStr for Mass

Source§

type Err = InvalidUnit

The associated error which can be returned from parsing.
Source§

fn from_str(value: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl PartialEq for Mass

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Mass

Source§

impl TryFrom<&str> for Mass

Source§

type Error = InvalidUnit

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

fn try_from(value: &str) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl Freeze for Mass

§

impl RefUnwindSafe for Mass

§

impl Send for Mass

§

impl Sync for Mass

§

impl Unpin for Mass

§

impl UnsafeUnpin for Mass

§

impl UnwindSafe for Mass

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.