Volume

Struct Volume 

Source
pub struct Volume { /* private fields */ }
Expand description

The Volume struct can be used to deal with volumes in a common way.

#Example

use measurements::Volume;

let gallon = Volume::from_gallons(1.0);
let pint = Volume::from_pints(1.0);
let beers = gallon / pint;
println!("A gallon of beer will pour {} pints!", beers);

Implementations§

Source§

impl Volume

Source

pub fn from_liters(liters: f64) -> Self

Create a new Volume from a floating point value in Liters (l)

Source

pub fn from_litres(liters: f64) -> Self

Create a new Volume from a floating point value in Litres (l)

Examples found in repository?
examples/format_test.rs (line 10)
3fn main() {
4    for power in -12..12 {
5        let val: f64 = 123.456 * (10f64.powf(f64::from(power)));
6        println!("10^{}...", power);
7        println!("Temp of {0:.3} outside", Temperature::from_kelvin(val));
8        println!("Distance of {0:.3}", Length::from_meters(val));
9        println!("Pressure of {0:.3}", Pressure::from_millibars(val));
10        println!("Volume of {0:.3}", Volume::from_litres(val));
11        println!("Mass of {0:.3}", Mass::from_kilograms(val));
12        println!("Speed of {0:.3}", Speed::from_meters_per_second(val));
13        println!(
14            "Acceleration of {0:.3}",
15            Acceleration::from_meters_per_second_per_second(val)
16        );
17        println!("Energy of {0:.3}", Energy::from_joules(val));
18        println!("Power of {0:.3}", Power::from_watts(val));
19        println!("Force of {0:.3}", Force::from_newtons(val));
20        println!("Force of {0:.3}", Torque::from_newton_metres(val));
21        println!(
22            "Force of {0:.3}",
23            AngularVelocity::from_radians_per_second(val)
24        );
25        println!("Data size is {0:.3}", Data::from_octets(val));
26    }
27}
Source

pub fn from_cubic_centimeters(cubic_centimeters: f64) -> Self

Create a new Volume from a floating point value in Cubic Centimeters (cc or cm³)

Source

pub fn from_cubic_centimetres(cubic_centimeters: f64) -> Self

Create a new Volume from a floating point value in Cubic Centimetres (cc or cm³)

Source

pub fn from_milliliters(milliliters: f64) -> Self

Create a new Volume from a floating point value in Milliliters (ml)

Source

pub fn from_millilitres(milliliters: f64) -> Self

Create a new Volume from a floating point value in Millilitres (ml)

Source

pub fn from_cubic_meters(cubic_meters: f64) -> Self

Create a new Volume from a floating point value in Cubic Meters (m³)

Source

pub fn from_cubic_metres(cubic_meters: f64) -> Self

Create a new Volume from a floating point value in Cubic Metres (m³)

Source

pub fn from_drops(drops: f64) -> Self

Create a new Volume from a floating point value in Drops

Source

pub fn from_drams(drams: f64) -> Self

Create a new Volume from a floating point value in US Fluid Drams

Source

pub fn from_teaspoons(teaspoons: f64) -> Self

Create a new Volume from a floating point value in Teaspoons (tsp)

Source

pub fn from_tablespoons(tablespoons: f64) -> Self

Create a new Volume from a floating point value in Tablespoons (tbsp)

Source

pub fn from_fluid_ounces_uk(fluid_ounces_uk: f64) -> Self

Create a new Volume from a floating point value in UK Fluid Ounces (fl oz)

Source

pub fn from_fluid_ounces(fluid_ounces: f64) -> Self

Create a new Volume from a floating point value in US Fluid Ounces (fl oz)

Source

pub fn from_cubic_inches(cubic_inches: f64) -> Self

Create a new Volume from a floating point value in Cubic Inches (cu in or in³)

Source

pub fn from_cups(cups: f64) -> Self

Create a new Volume from a floating point value in Cups

Source

pub fn from_pints(pints: f64) -> Self

Create a new Volume from a floating point value in US Pints

Source

pub fn from_pints_uk(pints_uk: f64) -> Self

Create a new Volume from a floating point value in UK Pints

Source

pub fn from_quarts(quarts: f64) -> Self

Create a new Volume from a floating point value in Quarts

Source

pub fn from_gallons(gallons: f64) -> Self

Create a new Volume from a floating point value in US Gallons (gal US)

Source

pub fn from_gallons_uk(gallons_uk: f64) -> Self

Create a new Volume from a floating point value in UK/Imperial Gallons (gal)

Source

pub fn from_cubic_feet(cubic_feet: f64) -> Self

Create a new Volume from a floating point value in Cubic Feet (ft³)

Source

pub fn from_cubic_yards(cubic_yards: f64) -> Self

Create a new Volume from a floating point value in Cubic Yards (yd³)

Source

pub fn as_cubic_centimeters(&self) -> f64

Convert Volume to a floating point value in Cubic Centimeters (cc or cm³)

Source

pub fn as_cubic_centimetres(&self) -> f64

Convert Volume to a floating point value in Cubic Centimetres (cc or cm³)

Source

pub fn as_milliliters(&self) -> f64

Convert Volume to a floating point value in Milliliters (ml)

Source

pub fn as_millilitres(&self) -> f64

Convert Volume to a floating point value in Millilitres (ml)

Source

pub fn as_liters(&self) -> f64

Convert Volume to a floating point value in Liters (l)

Source

pub fn as_litres(&self) -> f64

Convert Volume to a floating point value in Litres (l)

Source

pub fn as_cubic_meters(&self) -> f64

Convert Volume to a floating point value in Cubic Meters (m³)

Source

pub fn as_cubic_metres(&self) -> f64

Convert Volume to a floating point value in Cubic Metres (m³)

Source

pub fn as_drops(&self) -> f64

Convert Volume to a floating point value in Drops

Source

pub fn as_drams(&self) -> f64

Convert Volume to a floating point value in US Fluid Drams

Source

pub fn as_teaspoons(&self) -> f64

Convert Volume to a floating point value in Teaspoons (tsp)

Source

pub fn as_tablespoons(&self) -> f64

Convert Volume to a floating point value in Tablespoons (tbsp)

Source

pub fn as_cubic_inches(&self) -> f64

Convert Volume to a floating point value in Cubic Inches (cu in or in³)

Source

pub fn as_fluid_ounces_uk(&self) -> f64

Convert Volume to a floating point value in UK Fluid Ounces (fl oz)

Source

pub fn as_fluid_ounces(&self) -> f64

Convert Volume to a floating point value in US Fluid Ounces (fl oz)

Source

pub fn as_cups(&self) -> f64

Convert Volume to a floating point value in Cups

Source

pub fn as_pints(&self) -> f64

Convert Volume to a floating point value in US Pints

Source

pub fn as_pints_uk(&self) -> f64

Convert Volume to a floating point value in UK Pints

Source

pub fn as_quarts(&self) -> f64

Convert Volume to a floating point value in Quarts

Source

pub fn as_gallons(&self) -> f64

Convert Volume to a floating point value in US Gallons (gal us)

Source

pub fn as_gallons_uk(&self) -> f64

Convert Volume to a floating point value in UK/Imperial Gallons (gal)

Source

pub fn as_cubic_feet(&self) -> f64

Convert Volume to a floating point value in Cubic Feet (ft³)

Source

pub fn as_cubic_yards(&self) -> f64

Convert Volume to a floating point value in Cubic Yards (yd³)

Trait Implementations§

Source§

impl Add for Volume

Source§

type Output = Volume

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self

Performs the + operation. Read more
Source§

impl Clone for Volume

Source§

fn clone(&self) -> Volume

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Volume

Source§

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

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

impl Default for Volume

Source§

fn default() -> Volume

Returns the “default value” for a type. Read more
Source§

impl Display for Volume

Source§

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

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

impl Div<Area> for Volume

Source§

type Output = Length

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Area) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<Length> for Volume

Source§

type Output = Area

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Length) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<Volume> for Mass

Source§

type Output = Density

The resulting type after applying the / operator.
Source§

fn div(self, other: Volume) -> Density

Performs the / operation. Read more
Source§

impl Div<f64> for Volume

Source§

type Output = Volume

The resulting type after applying the / operator.
Source§

fn div(self, rhs: f64) -> Self

Performs the / operation. Read more
Source§

impl Div for Volume

Source§

type Output = f64

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Self) -> f64

Performs the / operation. Read more
Source§

impl Measurement for Volume

Source§

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
Source§

fn get_base_units_name(&self) -> &'static str

Return the base unit for this type, as a string. For example “kilograms”
Source§

fn as_base_units(&self) -> f64

Get this quantity in the base units
Source§

fn from_base_units(units: f64) -> Self

Create a new quantity from the base units
Source§

fn pick_appropriate_units( &self, list: &[(&'static str, f64)], ) -> (&'static str, f64)

Given a list of units and their scale relative to the base unit, select the most appropriate one. Read more
Source§

impl Mul<Density> for Volume

Source§

type Output = Mass

The resulting type after applying the * operator.
Source§

fn mul(self, other: Density) -> Mass

Performs the * operation. Read more
Source§

impl Mul<Volume> for Density

Source§

type Output = Mass

The resulting type after applying the * operator.
Source§

fn mul(self, other: Volume) -> Mass

Performs the * operation. Read more
Source§

impl Mul<Volume> for f64

Source§

type Output = Volume

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Volume) -> Volume

Performs the * operation. Read more
Source§

impl Mul<f64> for Volume

Source§

type Output = Volume

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: f64) -> Self

Performs the * operation. Read more
Source§

impl PartialEq for Volume

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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 PartialOrd for Volume

Source§

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 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Sub for Volume

Source§

type Output = Volume

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self

Performs the - operation. Read more
Source§

impl Copy for Volume

Source§

impl Eq for Volume

Auto Trait Implementations§

§

impl Freeze for Volume

§

impl RefUnwindSafe for Volume

§

impl Send for Volume

§

impl Sync for Volume

§

impl Unpin for Volume

§

impl UnwindSafe for Volume

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