Trait measurements::Measurement
[−]
[src]
pub trait Measurement { fn get_base_units_name(&self) -> &'static str; fn as_base_units(&self) -> f64; fn from_base_units(units: f64) -> Self; fn get_appropriate_units(&self) -> (&'static str, f64) { ... } fn pick_appropriate_units(
&self,
list: &[(&'static str, f64)]
) -> (&'static str, f64) { ... } }
All measurements implement this.
It provides conversion functions to and from raw numbers.
Required Methods
fn get_base_units_name(&self) -> &'static str
Return the base unit for this type, as a string. For example "kilograms"
fn as_base_units(&self) -> f64
Get this quantity in the base units
fn from_base_units(units: f64) -> Self
Create a new quantity from the base units
Provided Methods
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.
The default implementation always selects the base unit. Override in your Measurement impl to select better units if required.
fn pick_appropriate_units(
&self,
list: &[(&'static str, f64)]
) -> (&'static str, f64)
&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.
The list must be smallest to largest, e.g. ("nanometre", 10-9) to ("kilometre", 10e3)
Implementations on Foreign Types
impl Measurement for Duration
[src]
Implementors
impl Measurement for Length
impl Measurement for Temperature
impl Measurement for TemperatureDelta
impl Measurement for Mass
impl Measurement for Volume
impl Measurement for Pressure
impl Measurement for Speed
impl Measurement for Acceleration
impl Measurement for Energy
impl Measurement for Power
impl Measurement for Voltage
impl Measurement for Current
impl Measurement for Resistance
impl Measurement for Force
impl Measurement for Area
impl Measurement for Angle
impl Measurement for Frequency
impl Measurement for AngularVelocity
impl Measurement for Torque
impl Measurement for Data
impl Measurement for TorqueEnergy