Mercurial > templog
diff rust/src/types.rs @ 594:aff50ee77252 rust
rust working better now with streams and sinks.
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Wed, 04 Jan 2017 17:18:44 +0800 |
parents | bf138339d20a |
children | e87655ed8429 |
line wrap: on
line diff
--- a/rust/src/types.rs Tue Dec 27 00:51:28 2016 +0800 +++ b/rust/src/types.rs Wed Jan 04 17:18:44 2017 +0800 @@ -1,3 +1,6 @@ +use std::collections::HashMap; +use std::time::Duration; + #[derive(RustcDecodable, RustcEncodable, Debug, Clone)] pub struct Params { pub fridge_setpoint: f32, @@ -41,42 +44,40 @@ } #[derive(Debug)] -pub struct Reading { - name: String, - value: Option<f32>, -} - -impl Reading { - pub fn new(name: String, value: f32) -> Reading { - Reading { name: name, value: Some(value) } - } - pub fn new_none(name: String) -> Reading { - Reading { name: name, value: None } - } -} - -#[derive(Debug)] pub struct Readings { - temps: Vec<Vec<Reading>>, + temps: HashMap<String, Option<f32>>, } impl Readings { pub fn new() -> Readings { Readings { - temps: Vec::new(), + temps: HashMap::new(), } } - pub fn push(&mut self, vals: Vec<Reading>) { - self.temps.push(vals); + 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 fridge(&self) -> Option<f32> { - unimplemented!(); + if let Some(t) = self.temps.get("fridge") { + t.clone() + } else { + warn!("No fridge reading was added"); + None + } } pub fn wort(&self) -> Option<f32> { - unimplemented!(); + if let Some(t) = self.temps.get("wort") { + t.clone() + } else { + warn!("No wort reading was added"); + None + } } }