Mercurial > templog
comparison rust/src/types.rs @ 626:efcbe0d3afd6 rust
fix to work with hyper
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Wed, 06 Dec 2017 00:09:45 +0800 |
parents | 03167105f6de |
children | 490e9e15b98c |
comparison
equal
deleted
inserted
replaced
625:8152ef251dbb | 626:efcbe0d3afd6 |
---|---|
9 use std; | 9 use std; |
10 | 10 |
11 use futures::{Stream,IntoFuture}; | 11 use futures::{Stream,IntoFuture}; |
12 use serde::{Deserialize,Serialize}; | 12 use serde::{Deserialize,Serialize}; |
13 use toml; | 13 use toml; |
14 use curl; | 14 use hyper; |
15 use serde_json; | 15 use serde_json; |
16 | 16 |
17 #[derive(Debug)] | 17 #[derive(Debug)] |
18 pub struct Readings { | 18 pub struct Readings { |
19 pub temps: HashMap<String, f32>, | 19 pub temps: HashMap<String, f32>, |
40 None, | 40 None, |
41 Io(io::Error), | 41 Io(io::Error), |
42 ParseFloat(std::num::ParseFloatError), | 42 ParseFloat(std::num::ParseFloatError), |
43 TomlDe(toml::de::Error), | 43 TomlDe(toml::de::Error), |
44 SerdeJson(serde_json::Error), | 44 SerdeJson(serde_json::Error), |
45 Curl(curl::Error), | 45 Hyper(hyper::Error), |
46 } | 46 } |
47 | 47 |
48 #[derive(Debug)] | 48 #[derive(Debug)] |
49 pub struct TemplogError { | 49 pub struct TemplogError { |
50 msg: String, | 50 msg: String, |
62 TemplogErrorKind::None => None, | 62 TemplogErrorKind::None => None, |
63 TemplogErrorKind::Io(ref e) => Some(e), | 63 TemplogErrorKind::Io(ref e) => Some(e), |
64 TemplogErrorKind::ParseFloat(ref e) => Some(e), | 64 TemplogErrorKind::ParseFloat(ref e) => Some(e), |
65 TemplogErrorKind::TomlDe(ref e) => Some(e), | 65 TemplogErrorKind::TomlDe(ref e) => Some(e), |
66 TemplogErrorKind::SerdeJson(ref e) => Some(e), | 66 TemplogErrorKind::SerdeJson(ref e) => Some(e), |
67 TemplogErrorKind::Curl(ref e) => Some(e), | 67 TemplogErrorKind::Hyper(ref e) => Some(e), |
68 } | 68 } |
69 } | 69 } |
70 | 70 |
71 } | 71 } |
72 | 72 |
80 TemplogErrorKind::None => Ok(()), | 80 TemplogErrorKind::None => Ok(()), |
81 TemplogErrorKind::Io(ref e) => write!(f, ": {}", e), | 81 TemplogErrorKind::Io(ref e) => write!(f, ": {}", e), |
82 TemplogErrorKind::TomlDe(ref e) => write!(f, ": {}", e), | 82 TemplogErrorKind::TomlDe(ref e) => write!(f, ": {}", e), |
83 TemplogErrorKind::SerdeJson(ref e) => write!(f, ": {}", e), | 83 TemplogErrorKind::SerdeJson(ref e) => write!(f, ": {}", e), |
84 TemplogErrorKind::ParseFloat(ref e) => write!(f, ": {}", e), | 84 TemplogErrorKind::ParseFloat(ref e) => write!(f, ": {}", e), |
85 TemplogErrorKind::Curl(ref e) => write!(f, ": {}", e), | 85 TemplogErrorKind::Hyper(ref e) => write!(f, ": {}", e), |
86 }; | 86 }; |
87 Ok(()) | 87 Ok(()) |
88 } | 88 } |
89 } | 89 } |
90 | 90 |
103 | 103 |
104 pub fn new_parse_float(msg: &str, e: std::num::ParseFloatError) -> Self { | 104 pub fn new_parse_float(msg: &str, e: std::num::ParseFloatError) -> Self { |
105 TemplogError::new_kind(msg, TemplogErrorKind::ParseFloat(e)) | 105 TemplogError::new_kind(msg, TemplogErrorKind::ParseFloat(e)) |
106 } | 106 } |
107 | 107 |
108 pub fn new_curl(msg: &str, e: curl::Error) -> Self { | 108 pub fn new_hyper(msg: &str, e: hyper::Error) -> Self { |
109 TemplogError::new_kind(msg, TemplogErrorKind::Curl(e)) | 109 TemplogError::new_kind(msg, TemplogErrorKind::Hyper(e)) |
110 } | 110 } |
111 | 111 |
112 pub fn new_serde_json(msg: &str, e: serde_json::Error) -> Self { | 112 pub fn new_serde_json(msg: &str, e: serde_json::Error) -> Self { |
113 TemplogError::new_kind(msg, TemplogErrorKind::SerdeJson(e)) | 113 TemplogError::new_kind(msg, TemplogErrorKind::SerdeJson(e)) |
114 } | 114 } |
136 TemplogErrorKind::None => "Templog Error", | 136 TemplogErrorKind::None => "Templog Error", |
137 TemplogErrorKind::Io(_) => "Templog IO error", | 137 TemplogErrorKind::Io(_) => "Templog IO error", |
138 TemplogErrorKind::TomlDe(_) => "Templog toml error", | 138 TemplogErrorKind::TomlDe(_) => "Templog toml error", |
139 TemplogErrorKind::SerdeJson(_) => "Templog Json decode error", | 139 TemplogErrorKind::SerdeJson(_) => "Templog Json decode error", |
140 TemplogErrorKind::ParseFloat(_) => "Templog parse error", | 140 TemplogErrorKind::ParseFloat(_) => "Templog parse error", |
141 TemplogErrorKind::Curl(_) => "Templog curl http error", | 141 TemplogErrorKind::Hyper(_) => "Templog http error", |
142 } | 142 } |
143 } | 143 } |
144 } | 144 } |
145 | 145 |
146 impl From<io::Error> for TemplogError { | 146 impl From<io::Error> for TemplogError { |
159 fn from(e: std::num::ParseFloatError) -> Self { | 159 fn from(e: std::num::ParseFloatError) -> Self { |
160 TemplogError::new_parse_float("", e) | 160 TemplogError::new_parse_float("", e) |
161 } | 161 } |
162 } | 162 } |
163 | 163 |
164 impl From<curl::Error> for TemplogError { | 164 impl From<hyper::Error> for TemplogError { |
165 fn from(e: curl::Error) -> Self { | 165 fn from(e: hyper::Error) -> Self { |
166 TemplogError::new_curl("", e) | 166 TemplogError::new_hyper("", e) |
167 } | 167 } |
168 } | 168 } |
169 | 169 |
170 impl From<serde_json::Error> for TemplogError { | 170 impl From<serde_json::Error> for TemplogError { |
171 fn from(e: serde_json::Error) -> Self { | 171 fn from(e: serde_json::Error) -> Self { |