Struct measurements::density::Density
source · [−]pub struct Density { /* private fields */ }
Expand description
The Density
struct can be used to deal with Densities in a common way, to enable mass,
volume and density calculations and unit conversions.
Example1 - calculating volume from units of mass and density
extern crate measurements;
use measurements::{Density, Mass, Volume};
fn main() {
// Q: A 12 stone man hops into a brimming full bath, completely emersing himself.
// How many gallons of water spill on the floor?
// (Assume The human body is roughly about as dense as water - 1 gm/cm³)
//
let body_density: Density = Mass::from_grams(1.0) / Volume:: from_cubic_centimetres(1.0);
let mans_weight = Mass::from_stones(12.0);
let water_volume = mans_weight / body_density;
println!("{} gallons of water spilled on the floor", water_volume.as_gallons());
}
Example2 - converting to ad-hoc units of density
extern crate measurements;
use measurements::{Density, Mass, Volume};
fn main() {
// Q: what is 3 grams per litre in units of ounces per quart?
//
let density: Density = Mass::from_grams(3.0) / Volume:: from_litres(1.0);
let ounces = (density * Volume::from_quarts(1.0)).as_ounces();
println!("Answer is {} ounces per quart", ounces);
}
Implementations
sourceimpl Density
impl Density
sourcepub fn from_kilograms_per_cubic_meter(kilograms_per_cubic_meter: f64) -> Density
pub fn from_kilograms_per_cubic_meter(kilograms_per_cubic_meter: f64) -> Density
Create a new Density from a floating point value in kilograms per cubic meter
sourcepub fn from_pounds_per_cubic_feet(pounds_per_cubic_foot: f64) -> Density
pub fn from_pounds_per_cubic_feet(pounds_per_cubic_foot: f64) -> Density
Create a new Density from a floating point value in pounds per cubic feet
sourcepub fn as_kilograms_per_cubic_meter(&self) -> f64
pub fn as_kilograms_per_cubic_meter(&self) -> f64
Convert this Density to a value in kilograms per cubic meter
sourcepub fn as_pounds_per_cubic_feet(&self) -> f64
pub fn as_pounds_per_cubic_feet(&self) -> f64
Convert this Density to a value in pounds per cubic feet
Trait Implementations
sourceimpl Measurement for Density
impl Measurement for Density
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 PartialOrd<Density> for Density
impl PartialOrd<Density> for Density
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 Density
impl Eq for Density
Auto Trait Implementations
impl RefUnwindSafe for Density
impl Send for Density
impl Sync for Density
impl Unpin for Density
impl UnwindSafe for Density
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