Mercurial > templog
diff rust/src/types.rs @ 603:b45b8b4cf0f5 rust
get rid of lazy_static, config is passed around
better use of threadpool for sensors
readings are no longer options
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Thu, 16 Feb 2017 23:19:12 +0800 |
parents | ca8102feaca6 |
children | 278f1002b5c7 |
line wrap: on
line diff
--- a/rust/src/types.rs Thu Feb 16 23:17:51 2017 +0800 +++ b/rust/src/types.rs Thu Feb 16 23:19:12 2017 +0800 @@ -46,7 +46,7 @@ #[derive(Debug)] pub struct Readings { - temps: HashMap<String, Option<f32>>, + pub temps: HashMap<String, f32>, } impl Readings { @@ -56,29 +56,12 @@ } } - pub fn add(&mut self, name: &str, v: Option<f32>) { - if let Some(prev) = self.temps.insert(name.to_string(), v) { - warn!("Replaced existing reading '{}' {:?} -> {:?}", - name, prev, v); - } + pub fn add(&mut self, name: &str, v: f32) { + self.temps.insert(name.to_string(), v); } - pub fn fridge(&self) -> Option<f32> { - if let Some(t) = self.temps.get("fridge") { - t.clone() - } else { - warn!("No fridge reading was added"); - None - } - } - - pub fn wort(&self) -> Option<f32> { - if let Some(t) = self.temps.get("wort") { - t.clone() - } else { - warn!("No wort reading was added"); - None - } + pub fn get_temp(&self, name: &str) -> Option<f32> { + self.temps.get(name).map(|f| *f) } }