Crates.io | simmer |
lib.rs | simmer |
version | 0.3.0 |
source | src |
created_at | 2023-11-30 04:58:01.450677 |
updated_at | 2023-12-18 04:29:30.774012 |
description | A temperature unit library for Rust. It's intended to be minimal, embedded-aware, and easy to use! |
homepage | |
repository | https://github.com/onkoe/simmer |
max_upload_size | |
id | 1053864 |
size | 48,236 |
A Rust library crate that expresses some standard units of temperature. It's compatible with embedded systems, happily converts between units, and unwraps internal values when you're ready to leave.
Temperature
, a simple wrapper for a float that stores some temperatureCheckedTemperature
type, which only allows 'correct' temperaturesDisplay
, Debug
, and the ufmt
counterpartsf32
and f64
supportThere's not much detail to this crate. You can get started with the code below!
use simmer::Temperature;
fn main() {
let ice = Temperature::Fahrenheit(32.0);
println!("water freezes at {ice} degrees fahrenheit");
let ice_c = ice.to_celsius();
println!("water freezes at {ice_c} degrees celsius");
let ice_raw_c: f64 = ice_c.into();
println!("here's a number: {ice_raw_c}");
}
There's also a CheckedTemperature type to store and use temperatures safely. Here's a quick example of that:
fn main() -> anyhow::Result<()> {
let ice = CheckedTemperature::new(Temperature::Fahrenheit(32.0))?;
println!("water freezes at {ice} degrees fahrenheit");
let ice_c = ice.to_celsius()?;
let ice_raw_c: f64 = ice_c.into(); // can also use `f32` 😄
println!("here's a number: {ice_raw_c}");
Ok(())
}
If you feel that something is out of place (or you have a new feature), please feel free to submit a pull request! Particularly for bugs, you don't need to waste any time.
On the other hand, please create an issue before adding any new features. Thanks for your help in making this crate better! 🤩