Struct measurements::mass::Mass
source · [−]pub struct Mass { /* private fields */ }
Expand description
The Mass struct can be used to deal with mass in a common way. Metric, avoirdupois imperial and troy imperial units are supported.
#Example
use measurements::Mass;
let metric_ton = Mass::from_metric_tons(1.0);
let united_states_tons = metric_ton.as_short_tons();
let united_states_pounds = metric_ton.as_pounds();
println!(
"One metric ton is {} U.S. tons - that's {} pounds!",
united_states_tons, united_states_pounds);
Implementations
sourceimpl Mass
impl Mass
sourcepub fn from_kilograms(kilograms: f64) -> Self
pub fn from_kilograms(kilograms: f64) -> Self
Create a Mass from a floating point value in kilograms
sourcepub fn from_micrograms(micrograms: f64) -> Self
pub fn from_micrograms(micrograms: f64) -> Self
Create a Mass from a floating point value in micrograms
sourcepub fn from_milligrams(milligrams: f64) -> Self
pub fn from_milligrams(milligrams: f64) -> Self
Create a Mass from a floating point value in milligrams
sourcepub fn from_carats(carats: f64) -> Self
pub fn from_carats(carats: f64) -> Self
Create a Mass from a floating point value in carats
sourcepub fn from_grams(grams: f64) -> Self
pub fn from_grams(grams: f64) -> Self
Create a Mass from a floating point value in grams
sourcepub fn from_metric_tons(metric_tons: f64) -> Self
pub fn from_metric_tons(metric_tons: f64) -> Self
Create a Mass from a floating point value in metric tonnes
sourcepub fn from_tonnes(metric_tons: f64) -> Self
pub fn from_tonnes(metric_tons: f64) -> Self
Create a Mass from a floating point value in metric tonnes
sourcepub fn from_grains(grains: f64) -> Self
pub fn from_grains(grains: f64) -> Self
Create a Mass from a floating point value in grains
sourcepub fn from_pennyweights(pennyweights: f64) -> Self
pub fn from_pennyweights(pennyweights: f64) -> Self
Create a Mass from a floating point value in pennyweights
sourcepub fn from_ounces(ounces: f64) -> Self
pub fn from_ounces(ounces: f64) -> Self
Create a Mass from a floating point value in ounces
sourcepub fn from_troy_ounces(troy_ounces: f64) -> Self
pub fn from_troy_ounces(troy_ounces: f64) -> Self
Create a Mass from a floating point value in troy_ounces
sourcepub fn from_pounds(pounds: f64) -> Self
pub fn from_pounds(pounds: f64) -> Self
Create a Mass from a floating point value in Pounds (lbs)
sourcepub fn from_troy_pounds(troy_pounds: f64) -> Self
pub fn from_troy_pounds(troy_pounds: f64) -> Self
Create a Mass from a floating point value in Troy Pounds
sourcepub fn from_stones(stones: f64) -> Self
pub fn from_stones(stones: f64) -> Self
Create a Mass from a floating point value in Stone (st.)
sourcepub fn from_short_tons(short_tons: f64) -> Self
pub fn from_short_tons(short_tons: f64) -> Self
Create a Mass from a floating point value in short (US) tons
sourcepub fn from_long_tons(long_tons: f64) -> Self
pub fn from_long_tons(long_tons: f64) -> Self
Create a Mass from a floating point value in long (imperial) tons
sourcepub fn as_micrograms(&self) -> f64
pub fn as_micrograms(&self) -> f64
Convert this Mass to a floating point value in micrograms
sourcepub fn as_milligrams(&self) -> f64
pub fn as_milligrams(&self) -> f64
Convert this Mass to a floating point value in milligrams
sourcepub fn as_kilograms(&self) -> f64
pub fn as_kilograms(&self) -> f64
Convert this Mass to a floating point value in kilograms (kg)
sourcepub fn as_metric_tons(&self) -> f64
pub fn as_metric_tons(&self) -> f64
Convert this Mass to a floating point value in metric Tonnes
sourcepub fn as_pennyweights(&self) -> f64
pub fn as_pennyweights(&self) -> f64
Convert this Mass to a floating point value in Pennyweights
sourcepub fn as_troy_ounces(&self) -> f64
pub fn as_troy_ounces(&self) -> f64
Convert this Mass to a floating point value in Troy Ounces
sourcepub fn as_troy_pounds(&self) -> f64
pub fn as_troy_pounds(&self) -> f64
Convert this Mass to a floating point value in Troy Pounds
sourcepub fn as_short_tons(&self) -> f64
pub fn as_short_tons(&self) -> f64
Convert this Mass to a floating point value in short (US) Tons
sourcepub fn as_long_tons(&self) -> f64
pub fn as_long_tons(&self) -> f64
Convert this Mass to a floating point value in long (international) Tons
Trait Implementations
sourceimpl Measurement for Mass
impl Measurement for Mass
sourcefn as_base_units(&self) -> f64
fn as_base_units(&self) -> f64
Get this quantity in the base units
sourcefn from_base_units(units: f64) -> Self
fn from_base_units(units: f64) -> Self
Create a new quantity from the base units
sourcefn get_base_units_name(&self) -> &'static str
fn get_base_units_name(&self) -> &'static str
Return the base unit for this type, as a string. For example “kilograms” Read more
sourcefn get_appropriate_units(&self) -> (&'static str, f64)
fn get_appropriate_units(&self) -> (&'static str, f64)
Returns a string containing the most appropriate units for this quantity, and a floating point value representing this quantity in those units. Useful when, for example, a length might be in millimeters if it is very small, or kilometers when it is very large. Read more
sourceimpl Mul<Acceleration> for Mass
impl Mul<Acceleration> for Mass
sourceimpl Mul<Mass> for Acceleration
impl Mul<Mass> for Acceleration
sourceimpl PartialOrd<Mass> for Mass
impl PartialOrd<Mass> for Mass
sourcefn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl Copy for Mass
impl Eq for Mass
Auto Trait Implementations
impl RefUnwindSafe for Mass
impl Send for Mass
impl Sync for Mass
impl Unpin for Mass
impl UnwindSafe for Mass
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more