pub struct Unit<ExponentsType = DynDimensionExponents> {
pub name: &'static str,
pub symbols: &'static [&'static str],
pub scale: ScaleExponents,
pub conversion_factor: f64,
pub affine_offset: f64,
pub exponents: ExponentsType,
pub system: System,
}Expand description
A unit.
Each unit is assigned a “storage unit”. The storage unit is the unit of a value stored with this unit. Storage units are always a well defined multiple of an SI base unit.
The logarithmic scale encoding in the type system uses only powers of 2, 3, 5, and pi. This means that the storage unit must be a multiple of an SI base unit and a product of powers of 2, 3, 5, and pi. For example,
- “kilometer” has a scale factor of 10^3 = 2^3 * 5^3
- “degree” has a scale factor of π/180 = 2^-2 * 3^-2 * 5^-1 * pi^1
Units that differ from identity in their conversion_factor are “non-storage”
units. Non-storage units are not stored in their native scale; upon declaration
they are converted to their “nearest neighbor” power-of-10 multiple of a SI
base unit. For example
- “inch” is multiplied by 2.54 and stored as “centimeters”
- “yard” is multiplied by 0.9144 and stored as “meters”
- “mile” is multiplied by 1.609344 and stored as “kilometers”
Fields§
§name: &'static strName of the unit.
symbols: &'static [&'static str]Symbols associated with the unit.
Symbols are also used for lookup, so they must be unique within the unit system.
Because SI has a systematic prefixing semantics, symbols must be kept from colliding not just with the SI base symbols, but with any legal prefixing thereof. “SI base symbols” are defined as the first symbol of the first unit in each dimension, by declaration order.
scale: ScaleExponentsBase unit per storage unit.
To convert from a value in the storage unit to a SI base unit value,
multiply it by scale.
For example, a scale of 1000 in dimension length would store
the value as kilometers. If we have the value 123 stored then that
means in meters it is 123 * 1000 = 123,000 meters.
conversion_factor: f64Storage unit per this unit.
Difference from identity canonically identifies a unit as a “non-storage” unit. Non-storage units are not stored in their native scale, as arbitrary float scaling factors are not part of the logarithmic scale encoding in the type system.
To convert from a value in this unit to a storage unit value,
multiply it by conversion_factor.
For example, the “inch” unit has a conversion_factor of 2.54,
which means that a value of 1 in inches is stored as 2.54
(accordingly, the scale is 10^-2).
Non-storage units are always given a storage scale of their “nearest neighbor” power-of-10 multiple of a SI base unit. For example,
- “inch” is multiplied by 2.54 and stored as “centimeters”
- “yard” is multiplied by 0.9144 and stored as “meters”
- “mile” is multiplied by 1.609344 and stored as “kilometers”
affine_offset: f64The “zero point offset” of this unit’s measurement scale from the numerical zero of the storage unit.
To convert from a value in the unit to the storage unit, add the affine offset to the value.
For example, the “celsius” unit has an affine offset of 273.15,
which means that a value of 0 in celsius is stored as 273.15
in kelvin.
exponents: ExponentsTypeDimensional exponent vector of the dimension this unit belongs to.
system: SystemWhich “unit system” this unit belongs to. This determines the name of the declarator trait in which this unit’s nominal declarators will live (e.g. “ImperialLength” or “MetricMass”).
Implementations§
Source§impl<ExponentsType> Unit<ExponentsType>
impl<ExponentsType> Unit<ExponentsType>
Sourcepub fn has_conversion(&self) -> bool
pub fn has_conversion(&self) -> bool
Check if the unit has a conversion factor.
Sourcepub fn has_affine_offset(&self) -> bool
pub fn has_affine_offset(&self) -> bool
Check if the unit has an affine offset.
Source§impl<const MASS_EXP: i16, const LENGTH_EXP: i16, const TIME_EXP: i16, const CURRENT_EXP: i16, const TEMPERATURE_EXP: i16, const AMOUNT_EXP: i16, const LUMINOSITY_EXP: i16, const ANGLE_EXP: i16> Unit<TypeDimensionExponents<_M<MASS_EXP>, _L<LENGTH_EXP>, _T<TIME_EXP>, _I<CURRENT_EXP>, _Θ<TEMPERATURE_EXP>, _N<AMOUNT_EXP>, _J<LUMINOSITY_EXP>, _A<ANGLE_EXP>>>
impl<const MASS_EXP: i16, const LENGTH_EXP: i16, const TIME_EXP: i16, const CURRENT_EXP: i16, const TEMPERATURE_EXP: i16, const AMOUNT_EXP: i16, const LUMINOSITY_EXP: i16, const ANGLE_EXP: i16> Unit<TypeDimensionExponents<_M<MASS_EXP>, _L<LENGTH_EXP>, _T<TIME_EXP>, _I<CURRENT_EXP>, _Θ<TEMPERATURE_EXP>, _N<AMOUNT_EXP>, _J<LUMINOSITY_EXP>, _A<ANGLE_EXP>>>
Source§impl Unit
Lists of units.
impl Unit
Lists of units.
pub const BASES: [Self; 8]
Source§impl Unit<TypeDimensionExponents<_M<1>, _L<0>, _T<0>, _I<0>, _Θ<0>, _N<0>, _J<0>, _A<0>>>
Mass
impl Unit<TypeDimensionExponents<_M<1>, _L<0>, _T<0>, _I<0>, _Θ<0>, _N<0>, _J<0>, _A<0>>>
Mass
Source§impl Unit<TypeDimensionExponents<_M<0>, _L<1>, _T<0>, _I<0>, _Θ<0>, _N<0>, _J<0>, _A<0>>>
Length
impl Unit<TypeDimensionExponents<_M<0>, _L<1>, _T<0>, _I<0>, _Θ<0>, _N<0>, _J<0>, _A<0>>>
Length
pub const METER: Self
pub const INCH: Self
pub const FOOT: Self
pub const YARD: Self
pub const FATHOM: Self
pub const FURLONG: Self
pub const MILE: Self
pub const NAUTICAL_MILE: Self
pub const ASTRONOMICAL_UNIT: Self
pub const LIGHT_YEAR: Self
pub const PARSEC: Self
Source§impl Unit<TypeDimensionExponents<_M<0>, _L<0>, _T<1>, _I<0>, _Θ<0>, _N<0>, _J<0>, _A<0>>>
Time
impl Unit<TypeDimensionExponents<_M<0>, _L<0>, _T<1>, _I<0>, _Θ<0>, _N<0>, _J<0>, _A<0>>>
Time
Source§impl Unit<TypeDimensionExponents<_M<0>, _L<0>, _T<0>, _I<1>, _Θ<0>, _N<0>, _J<0>, _A<0>>>
Current
impl Unit<TypeDimensionExponents<_M<0>, _L<0>, _T<0>, _I<1>, _Θ<0>, _N<0>, _J<0>, _A<0>>>
Current
Source§impl Unit<TypeDimensionExponents<_M<0>, _L<0>, _T<0>, _I<0>, _Θ<1>, _N<0>, _J<0>, _A<0>>>
Temperature
impl Unit<TypeDimensionExponents<_M<0>, _L<0>, _T<0>, _I<0>, _Θ<1>, _N<0>, _J<0>, _A<0>>>
Temperature
Source§impl Unit<TypeDimensionExponents<_M<0>, _L<0>, _T<0>, _I<0>, _Θ<0>, _N<1>, _J<0>, _A<0>>>
Amount
impl Unit<TypeDimensionExponents<_M<0>, _L<0>, _T<0>, _I<0>, _Θ<0>, _N<1>, _J<0>, _A<0>>>
Amount
Source§impl Unit<TypeDimensionExponents<_M<0>, _L<0>, _T<0>, _I<0>, _Θ<0>, _N<0>, _J<0>, _A<1>>>
Angle
impl Unit<TypeDimensionExponents<_M<0>, _L<0>, _T<0>, _I<0>, _Θ<0>, _N<0>, _J<0>, _A<1>>>
Angle
Source§impl Unit<TypeDimensionExponents<_M<0>, _L<0>, _T<-1>, _I<0>, _Θ<0>, _N<0>, _J<0>, _A<0>>>
Frequency
impl Unit<TypeDimensionExponents<_M<0>, _L<0>, _T<-1>, _I<0>, _Θ<0>, _N<0>, _J<0>, _A<0>>>
Frequency
Source§impl Unit<TypeDimensionExponents<_M<1>, _L<1>, _T<-2>, _I<0>, _Θ<0>, _N<0>, _J<0>, _A<0>>>
Force
impl Unit<TypeDimensionExponents<_M<1>, _L<1>, _T<-2>, _I<0>, _Θ<0>, _N<0>, _J<0>, _A<0>>>
Force
Source§impl Unit<TypeDimensionExponents<_M<1>, _L<2>, _T<-2>, _I<0>, _Θ<0>, _N<0>, _J<0>, _A<0>>>
Energy and work
impl Unit<TypeDimensionExponents<_M<1>, _L<2>, _T<-2>, _I<0>, _Θ<0>, _N<0>, _J<0>, _A<0>>>
Energy and work
pub const JOULE: Self
pub const NEWTON_METER: Self
pub const ELECTRONVOLT: Self
pub const ERG: Self
pub const CALORIE: Self
pub const FOOT_POUND: Self
pub const KILOWATT_HOUR: Self
pub const THERM: Self
Source§impl Unit<TypeDimensionExponents<_M<1>, _L<2>, _T<-3>, _I<0>, _Θ<0>, _N<0>, _J<0>, _A<0>>>
Power
impl Unit<TypeDimensionExponents<_M<1>, _L<2>, _T<-3>, _I<0>, _Θ<0>, _N<0>, _J<0>, _A<0>>>
Power
pub const WATT: Self
pub const HORSEPOWER: Self
Source§impl Unit<TypeDimensionExponents<_M<1>, _L<-1>, _T<-2>, _I<0>, _Θ<0>, _N<0>, _J<0>, _A<0>>>
Pressure
impl Unit<TypeDimensionExponents<_M<1>, _L<-1>, _T<-2>, _I<0>, _Θ<0>, _N<0>, _J<0>, _A<0>>>
Pressure
Source§impl Unit<TypeDimensionExponents<_M<0>, _L<0>, _T<1>, _I<1>, _Θ<0>, _N<0>, _J<0>, _A<0>>>
Electric charge
impl Unit<TypeDimensionExponents<_M<0>, _L<0>, _T<1>, _I<1>, _Θ<0>, _N<0>, _J<0>, _A<0>>>
Electric charge
Source§impl Unit<TypeDimensionExponents<_M<1>, _L<2>, _T<-3>, _I<-1>, _Θ<0>, _N<0>, _J<0>, _A<0>>>
Electric potential
impl Unit<TypeDimensionExponents<_M<1>, _L<2>, _T<-3>, _I<-1>, _Θ<0>, _N<0>, _J<0>, _A<0>>>
Electric potential
Source§impl Unit<TypeDimensionExponents<_M<-1>, _L<-2>, _T<4>, _I<2>, _Θ<0>, _N<0>, _J<0>, _A<0>>>
Capacitance
impl Unit<TypeDimensionExponents<_M<-1>, _L<-2>, _T<4>, _I<2>, _Θ<0>, _N<0>, _J<0>, _A<0>>>
Capacitance
Source§impl Unit<TypeDimensionExponents<_M<-1>, _L<-2>, _T<3>, _I<2>, _Θ<0>, _N<0>, _J<0>, _A<0>>>
Electric conductance
impl Unit<TypeDimensionExponents<_M<-1>, _L<-2>, _T<3>, _I<2>, _Θ<0>, _N<0>, _J<0>, _A<0>>>
Electric conductance
Source§impl Unit<TypeDimensionExponents<_M<1>, _L<2>, _T<-2>, _I<-2>, _Θ<0>, _N<0>, _J<0>, _A<0>>>
Inductance
impl Unit<TypeDimensionExponents<_M<1>, _L<2>, _T<-2>, _I<-2>, _Θ<0>, _N<0>, _J<0>, _A<0>>>
Inductance
Source§impl Unit<TypeDimensionExponents<_M<1>, _L<0>, _T<-2>, _I<-1>, _Θ<0>, _N<0>, _J<0>, _A<0>>>
Magnetic field
impl Unit<TypeDimensionExponents<_M<1>, _L<0>, _T<-2>, _I<-1>, _Θ<0>, _N<0>, _J<0>, _A<0>>>
Magnetic field
Source§impl Unit<TypeDimensionExponents<_M<1>, _L<2>, _T<-2>, _I<-1>, _Θ<0>, _N<0>, _J<0>, _A<0>>>
Magnetic flex
impl Unit<TypeDimensionExponents<_M<1>, _L<2>, _T<-2>, _I<-1>, _Θ<0>, _N<0>, _J<0>, _A<0>>>
Magnetic flex
Source§impl Unit<TypeDimensionExponents<_M<0>, _L<-2>, _T<0>, _I<0>, _Θ<0>, _N<0>, _J<1>, _A<0>>>
Illuminance
impl Unit<TypeDimensionExponents<_M<0>, _L<-2>, _T<0>, _I<0>, _Θ<0>, _N<0>, _J<1>, _A<0>>>
Illuminance
Source§impl Unit<TypeDimensionExponents<_M<0>, _L<0>, _T<0>, _I<0>, _Θ<0>, _N<0>, _J<1>, _A<0>>>
Luminous intensity
impl Unit<TypeDimensionExponents<_M<0>, _L<0>, _T<0>, _I<0>, _Θ<0>, _N<0>, _J<1>, _A<0>>>
Luminous intensity
Source§impl Unit<TypeDimensionExponents<_M<0>, _L<2>, _T<-1>, _I<0>, _Θ<0>, _N<0>, _J<0>, _A<0>>>
Kinematic viscosity
impl Unit<TypeDimensionExponents<_M<0>, _L<2>, _T<-1>, _I<0>, _Θ<0>, _N<0>, _J<0>, _A<0>>>
Kinematic viscosity
Source§impl Unit<TypeDimensionExponents<_M<0>, _L<2>, _T<0>, _I<0>, _Θ<0>, _N<0>, _J<0>, _A<0>>>
Area
impl Unit<TypeDimensionExponents<_M<0>, _L<2>, _T<0>, _I<0>, _Θ<0>, _N<0>, _J<0>, _A<0>>>
Area
Source§impl Unit<TypeDimensionExponents<_M<0>, _L<3>, _T<0>, _I<0>, _Θ<0>, _N<0>, _J<0>, _A<0>>>
Volume
impl Unit<TypeDimensionExponents<_M<0>, _L<3>, _T<0>, _I<0>, _Θ<0>, _N<0>, _J<0>, _A<0>>>
Volume