pub trait Unit {
// Required methods
fn to_base(&self) -> f64;
fn to_value(&self) -> f64;
fn set_value(&mut self, value: f64);
fn set_from_base(&mut self, base: f64);
fn from_base(base: f64) -> Self
where Self: Sized;
}Expand description
A unit of measurement.
For the purpose of this crate, a unit of measurement is defined purely by its conversion to a base unit of the same quantity.
The choice of the base unit is arbitrary and up to the implementor (although choosing a SI base is a good idea).
It is up to the implementor to additionally mark the implementing type with
a trait defining its associated quantity (e.g. Mass, Length, etc.).
Required Methods§
Sourcefn to_base(&self) -> f64
fn to_base(&self) -> f64
Converts the quantity value represented in this unit to its equivalent value in the base unit.
Sourcefn set_from_base(&mut self, base: f64)
fn set_from_base(&mut self, base: f64)
Set the wrapped value to one obtained by converting the passed f64,
assuming the passed value is in base units.