packages

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 Temperature

An 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).

nabi
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
  • pub const fn from_kelvin(k: f64) -> Temperature§

    Source

    The reading k kelvin.

    nabi
    use units::Temperature;
    
    assert(Temperature::from_kelvin(0.0).celsius() == -273.15);
    
  • pub const fn from_celsius(c: f64) -> Temperature§

    Source

    The reading c degrees Celsius.

    nabi
    use units::Temperature;
    
    assert(Temperature::from_celsius(100.0).kelvin() == 373.15);
    
  • pub const fn from_fahrenheit(f: f64) -> Temperature§

    Source

    The reading f degrees Fahrenheit.

    nabi
    use units::Temperature;
    
    assert(Temperature::from_fahrenheit(-40.0).celsius() == -40.0);
    
  • pub const fn from_rankine(r: f64) -> Temperature§

    Source

    The reading r degrees Rankine.

    nabi
    use units::Temperature;
    
    assert(Temperature::from_rankine(491.67).celsius() == 0.0);
    
  • pub const fn on(scale: Scale, v: f64) -> Temperature§

    Source

    The reading v on scale.

    nabi
    use units::Temperature;
    use units::temperature::Scale;
    
    assert(Temperature::on(Scale::Celsius, 25.0) == 25degC);
    
  • pub const fn from_absolute(t: ThermodynamicTemperature) -> Temperature§

    Source

    The reading for an absolute thermodynamic temperature.

    nabi
    use units::Temperature;
    
    assert(Temperature::from_absolute(300K).kelvin() == 300.0);
    
  • pub const fn kelvin(self) -> f64§

    Source

    In kelvin.

    nabi
    assert(0degC.kelvin() == 273.15);
    
  • pub const fn celsius(self) -> f64§

    Source

    In degrees Celsius.

    nabi
    assert(32degF.celsius() == 0.0);
    
  • pub const fn fahrenheit(self) -> f64§

    Source

    In degrees Fahrenheit.

    nabi
    assert(100degC.fahrenheit() == 212.0);
    
  • pub const fn rankine(self) -> f64§

    Source

    In degrees Rankine.

    nabi
    assert(0degF.rankine() == 459.67);
    
  • pub const fn on_scale(self, scale: Scale) -> f64§

    Source

    The value on scale.

    nabi
    use units::temperature::Scale;
    
    assert(20degC.on_scale(Scale::Fahrenheit) == 68.0);
    
  • pub const fn scale(self) -> Scale§

    Source

    The scale the reading was made on.

    nabi
    use units::temperature::Scale;
    
    assert(20degC.scale() == Scale::Celsius);
    
  • pub const fn absolute(self) -> ThermodynamicTemperature§

    Source

    The thermodynamic temperature, a kelvin Quantity for formulas (k_B * T).

    nabi
    assert(25degC.absolute() == 298.15K);
    
  • pub fn to(self, scale: Scale) -> Measure§

    Source

    The reading on scale, for printing: 20degC.to(degF) prints 68 °F.

    nabi
    use units::symbols::degF;
    
    assert(20degC.to(degF).value == 68.0);
    
Trait implementations 7
  • impl Display for Temperature
  • impl PartialEq for Temperature
  • impl PartialOrd for Temperature
  • impl ops::Neg for Temperature
  • impl ops::Sub for Temperature
  • impl ops::Add<Quantity<f64, 0, 0, 0, 0, 1, 0, 0>> for Temperature
  • impl ops::Sub<Quantity<f64, 0, 0, 0, 0, 1, 0, 0>> for Temperature

Enums

ScaleSource

pub enum Scale

A temperature scale.

nabi
use units::temperature::Scale;

assert(Scale::Fahrenheit.symbol() == "°F");
  • Kelvin§

    Source

    Kelvin, absolute.

  • Celsius§

    Source

    Celsius: kelvin minus 273.15.

  • Fahrenheit§

    Source

    Fahrenheit: 9/5 Celsius plus 32.

  • Rankine§

    Source

    Rankine: 9/5 kelvin.

  • pub const fn symbol(self) -> str§

    Source

    The symbol: K, °C, °F, °R.

    nabi
    use units::temperature::Scale;
    
    assert(Scale::Celsius.symbol() == "°C");
    
  • pub fn of_unit(u: DynUnit) -> Scale | none§

    Source

    The scale a dynamic unit stands for, by its size and offset (degC, °F, K, degR), or none.

    nabi
    use 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);
    
  • pub fn unit(self) -> DynUnit§

    Source

    The scale as a dynamic unit with its offset, for Measure.

    nabi
    use units::temperature::Scale;
    
    assert(Scale::Celsius.unit().offset == 273.15);