comparison 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
comparison
equal deleted inserted replaced
602:613f114feb4b 603:b45b8b4cf0f5
44 } 44 }
45 } 45 }
46 46
47 #[derive(Debug)] 47 #[derive(Debug)]
48 pub struct Readings { 48 pub struct Readings {
49 temps: HashMap<String, Option<f32>>, 49 pub temps: HashMap<String, f32>,
50 } 50 }
51 51
52 impl Readings { 52 impl Readings {
53 pub fn new() -> Readings { 53 pub fn new() -> Readings {
54 Readings { 54 Readings {
55 temps: HashMap::new(), 55 temps: HashMap::new(),
56 } 56 }
57 } 57 }
58 58
59 pub fn add(&mut self, name: &str, v: Option<f32>) { 59 pub fn add(&mut self, name: &str, v: f32) {
60 if let Some(prev) = self.temps.insert(name.to_string(), v) { 60 self.temps.insert(name.to_string(), v);
61 warn!("Replaced existing reading '{}' {:?} -> {:?}",
62 name, prev, v);
63 }
64 } 61 }
65 62
66 pub fn fridge(&self) -> Option<f32> { 63 pub fn get_temp(&self, name: &str) -> Option<f32> {
67 if let Some(t) = self.temps.get("fridge") { 64 self.temps.get(name).map(|f| *f)
68 t.clone()
69 } else {
70 warn!("No fridge reading was added");
71 None
72 }
73 }
74
75 pub fn wort(&self) -> Option<f32> {
76 if let Some(t) = self.temps.get("wort") {
77 t.clone()
78 } else {
79 warn!("No wort reading was added");
80 None
81 }
82 } 65 }
83 } 66 }
84 67