pub enum Temperature {
Fahrenheit(f64),
Celsius(f64),
Kelvin(f64),
}Expand description
A value that’s one of many common temperature units.
Wraps a floating point number to give it a unit!
You can create a new Temperature by putting a float value inside.
Important: Temperature is not checked, so invalid states are
completely allowed.
use simmer::Temperature;
let my_temp = Temperature::Celsius(0.0);Variants§
Implementations§
Source§impl Temperature
impl Temperature
Sourcepub fn to_fahrenheit(&self) -> Temperature
pub fn to_fahrenheit(&self) -> Temperature
Return a Temperature in Fahrenheit based off of Self.
§Usage
let body_temp_c = Temperature::Celsius(37.0);
let body_temp_f = body_temp_c.to_fahrenheit();
assert_approx_eq!(body_temp_f.into_inner(), 98.6);Sourcepub fn to_celsius(&self) -> Temperature
pub fn to_celsius(&self) -> Temperature
Return a Temperature in Celsius based off of Self.
§Usage
let body_temp_f = Temperature::Fahrenheit(98.6);
let body_temp_c = body_temp_f.to_celsius();
assert_approx_eq!(body_temp_c.into_inner(), 37.0);Sourcepub fn to_kelvin(&self) -> Temperature
pub fn to_kelvin(&self) -> Temperature
Return a Temperature in Kelvin based off of Self.
§Usage
let abs_zero_k = Temperature::Kelvin(0.0);
let abs_zero_c = abs_zero_k.to_celsius();
assert_approx_eq!(abs_zero_c.into_inner(), -273.15);Sourcepub fn into_inner(self) -> f64
pub fn into_inner(self) -> f64
A discovery function that returns the inner type, consuming the outer Temperature type.
Use my_temp.into() when possible.
§Usage
let my_temp = Temperature::Fahrenheit(98.6);
let my_temp_float = my_temp.into_inner();Sourcepub const fn get_inner(&self) -> f64
pub const fn get_inner(&self) -> f64
Gets the inner floating point value.
§Usage
let temp = Temperature::Kelvin(0.0);
let temp_inner = temp.get_inner();
println!("{temp:?}'s inner is {temp_inner}");Sourcepub fn is_below_abs_zero(&self) -> bool
pub fn is_below_abs_zero(&self) -> bool
Tells you if a Temperature is below absolute zero - an invalid state for temperature.
So… returns:
trueift>= abs zerofalseift< abs zero
§Usage
let temp = Temperature::Kelvin(0.0);
assert!(!temp.is_below_abs_zero());
let temp2 = Temperature::Kelvin(-0.1);
assert!(temp2.is_below_abs_zero());Trait Implementations§
Source§impl Add for Temperature
impl Add for Temperature
Source§type Output = Temperature
type Output = Temperature
The resulting type after applying the
+ operator.Source§fn add(self, rhs: Temperature) -> <Temperature as Add>::Output
fn add(self, rhs: Temperature) -> <Temperature as Add>::Output
Performs the
+ operation. Read moreSource§impl Clone for Temperature
impl Clone for Temperature
Source§fn clone(&self) -> Temperature
fn clone(&self) -> Temperature
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for Temperature
impl Debug for Temperature
Source§impl Display for Temperature
impl Display for Temperature
Source§impl Div<f64> for Temperature
impl Div<f64> for Temperature
Source§impl Into<f64> for Temperature
impl Into<f64> for Temperature
Source§impl Mul<f64> for Temperature
impl Mul<f64> for Temperature
Source§impl PartialEq for Temperature
impl PartialEq for Temperature
Source§impl PartialOrd for Temperature
impl PartialOrd for Temperature
Source§impl Sub for Temperature
impl Sub for Temperature
Source§type Output = Temperature
type Output = Temperature
The resulting type after applying the
- operator.Source§fn sub(self, rhs: Temperature) -> <Temperature as Sub>::Output
fn sub(self, rhs: Temperature) -> <Temperature as Sub>::Output
Performs the
- operation. Read moreSource§impl uDebug for Temperature
impl uDebug for Temperature
Source§impl uDisplay for Temperature
impl uDisplay for Temperature
impl Copy for Temperature
impl StructuralPartialEq for Temperature
Auto Trait Implementations§
impl Freeze for Temperature
impl RefUnwindSafe for Temperature
impl Send for Temperature
impl Sync for Temperature
impl Unpin for Temperature
impl UnwindSafe for Temperature
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more