Trait measurements::prelude::Measurement
source · [−]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) { ... }
}
Expand description
All measurements implement this.
It provides conversion functions to and from raw numbers.
Required methods
fn 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”
fn as_base_units(&self) -> f64
fn as_base_units(&self) -> f64
Get this quantity in the base units
fn from_base_units(units: f64) -> Self
fn from_base_units(units: f64) -> Self
Create a new quantity from the base units
Provided methods
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.