units::temperature
On this page
Temperature readings on the Kelvin, Celsius, Fahrenheit and Rankine
scales. A reading is a point, not an amount: two readings subtract
to a difference (a kelvin Quantity), a difference adds to a
reading, and adding two readings does not compile, so 20degC + 10degC cannot quietly mean 576.3 K.
Structs
TemperatureSource
pub struct TemperatureAn absolute temperature, a reading on any scale. 20degC,
68degF and Temperature::from_kelvin(293.15) are one value. The
reading keeps its own scale, so converting between Celsius and
Fahrenheit takes one exact step (20degC is exactly 68degF).
use units::Temperature;
use units::symbols::{degF, K};
let t = 20degC;
assert(t.fahrenheit() == 68.0);
let warmer = t + 5K;
assert(warmer - t == 5K);
println(t.to(degF)); // 68 °F
The reading
kkelvin.nabiuse units::Temperature; assert(Temperature::from_kelvin(0.0).celsius() == -273.15);The reading
cdegrees Celsius.nabiuse units::Temperature; assert(Temperature::from_celsius(100.0).kelvin() == 373.15);The reading
fdegrees Fahrenheit.nabiuse units::Temperature; assert(Temperature::from_fahrenheit(-40.0).celsius() == -40.0);The reading
rdegrees Rankine.nabiuse units::Temperature; assert(Temperature::from_rankine(491.67).celsius() == 0.0);The reading
vonscale.nabiuse units::Temperature; use units::temperature::Scale; assert(Temperature::on(Scale::Celsius, 25.0) == 25degC);
Sourcepub const fn from_absolute(§t: ThermodynamicTemperature) -> Temperature The reading for an absolute thermodynamic temperature.
nabiuse units::Temperature; assert(Temperature::from_absolute(300K).kelvin() == 300.0);In kelvin.
nabiassert(0degC.kelvin() == 273.15);In degrees Celsius.
nabiassert(32degF.celsius() == 0.0);In degrees Fahrenheit.
nabiassert(100degC.fahrenheit() == 212.0);In degrees Rankine.
nabiassert(0degF.rankine() == 459.67);The value on
scale.nabiuse units::temperature::Scale; assert(20degC.on_scale(Scale::Fahrenheit) == 68.0);The scale the reading was made on.
nabiuse units::temperature::Scale; assert(20degC.scale() == Scale::Celsius);
Sourcepub const fn absolute(§self) -> ThermodynamicTemperature The thermodynamic temperature, a kelvin
Quantityfor formulas (k_B * T).nabiassert(25degC.absolute() == 298.15K);The reading on
scale, for printing:20degC.to(degF)prints68 °F.nabiuse units::symbols::degF; assert(20degC.to(degF).value == 68.0);
Trait implementations 7
Enums
ScaleSource
pub enum ScaleA temperature scale.
use units::temperature::Scale;
assert(Scale::Fahrenheit.symbol() == "°F");
Kelvin, absolute.
Celsius: kelvin minus 273.15.
Fahrenheit: 9/5 Celsius plus 32.
Rankine: 9/5 kelvin.
The symbol:
K,°C,°F,°R.nabiuse units::temperature::Scale; assert(Scale::Celsius.symbol() == "°C");The scale a dynamic unit stands for, by its size and offset (
degC,°F,K,degR), ornone.nabiuse units::DynUnit; use units::temperature::Scale; assert(Scale::of_unit(try! DynUnit::parse("°F")) == Scale::Fahrenheit); assert(Scale::of_unit(try! DynUnit::parse("m")) == none);The scale as a dynamic unit with its offset, for
Measure.nabiuse units::temperature::Scale; assert(Scale::Celsius.unit().offset == 273.15);