annotate rust/src/types.rs @ 611:f3e39e2107fd rust

still doesn't compile, improvements to TemplogError and tokio curl though
author Matt Johnston <matt@ucc.asn.au>
date Tue, 28 Feb 2017 22:58:47 +0800
parents af0dac00d40b
children 5fc41e0833b4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
594
aff50ee77252 rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents: 593
diff changeset
1 use std::collections::HashMap;
609
7bda01659426 not building, paramwaiter work
Matt Johnston <matt@ucc.asn.au>
parents: 604
diff changeset
2 use std::time::{Duration,Instant};
604
278f1002b5c7 sensor regex, custom error type
Matt Johnston <matt@ucc.asn.au>
parents: 603
diff changeset
3 use std::error::Error;
278f1002b5c7 sensor regex, custom error type
Matt Johnston <matt@ucc.asn.au>
parents: 603
diff changeset
4 use std::fmt;
611
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
5 use std::io;
610
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
6 use std::cmp;
609
7bda01659426 not building, paramwaiter work
Matt Johnston <matt@ucc.asn.au>
parents: 604
diff changeset
7 use std::cell::Cell;
610
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
8 use std::iter::FromIterator;
611
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
9 use std;
604
278f1002b5c7 sensor regex, custom error type
Matt Johnston <matt@ucc.asn.au>
parents: 603
diff changeset
10
611
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
11 use futures::{Stream,IntoFuture};
595
e87655ed8429 add config
Matt Johnston <matt@ucc.asn.au>
parents: 594
diff changeset
12 use serde::{Deserialize,Serialize};
611
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
13 use toml;
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
14 use curl;
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
15 use serde_json;
594
aff50ee77252 rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents: 593
diff changeset
16
596
ca8102feaca6 sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents: 595
diff changeset
17 #[derive(Deserialize, Serialize, Debug)]
592
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
18 pub struct Params {
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
19 pub fridge_setpoint: f32,
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
20 pub fridge_difference: f32,
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
21 pub overshoot_delay: u32,
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
22 pub overshoot_factor: f32,
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
23 pub disabled: bool,
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
24 pub nowort: bool,
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
25 pub fridge_range_lower: f32,
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
26 pub fridge_range_upper: f32,
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
27 }
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
28
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
29 impl Params {
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
30 pub fn defaults() -> Params {
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
31 Params {
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
32 fridge_setpoint: 16.0,
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
33 fridge_difference: 0.2,
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
34 overshoot_delay: 720, // 12 minutes
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
35 overshoot_factor: 1.0,
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
36 disabled: false,
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
37 nowort: false,
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
38 fridge_range_lower: 3.0,
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
39 fridge_range_upper: 3.0,
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
40 }
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
41 }
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
42 }
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
43
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
44 #[derive(Debug)]
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
45 pub struct ParamHolder {
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
46 pub p: Params,
609
7bda01659426 not building, paramwaiter work
Matt Johnston <matt@ucc.asn.au>
parents: 604
diff changeset
47 epoch: String,
592
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
48 }
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
49
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
50 impl ParamHolder {
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
51 pub fn new() -> ParamHolder {
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
52 ParamHolder {
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
53 p: Params::defaults(),
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
54 epoch: String::new(),
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
55 }
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
56 }
609
7bda01659426 not building, paramwaiter work
Matt Johnston <matt@ucc.asn.au>
parents: 604
diff changeset
57
7bda01659426 not building, paramwaiter work
Matt Johnston <matt@ucc.asn.au>
parents: 604
diff changeset
58 pub fn receive(&mut self, p: &Params, epoch: &String)
7bda01659426 not building, paramwaiter work
Matt Johnston <matt@ucc.asn.au>
parents: 604
diff changeset
59 {
7bda01659426 not building, paramwaiter work
Matt Johnston <matt@ucc.asn.au>
parents: 604
diff changeset
60
7bda01659426 not building, paramwaiter work
Matt Johnston <matt@ucc.asn.au>
parents: 604
diff changeset
61 }
592
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
62 }
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
63
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
64 #[derive(Debug)]
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
65 pub struct Readings {
603
b45b8b4cf0f5 get rid of lazy_static, config is passed around
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
66 pub temps: HashMap<String, f32>,
592
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
67 }
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
68
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
69 impl Readings {
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
70 pub fn new() -> Readings {
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
71 Readings {
594
aff50ee77252 rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents: 593
diff changeset
72 temps: HashMap::new(),
592
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
73 }
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
74 }
593
bf138339d20a fiddling with timeouts and closures
Matt Johnston <matt@ucc.asn.au>
parents: 592
diff changeset
75
603
b45b8b4cf0f5 get rid of lazy_static, config is passed around
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
76 pub fn add(&mut self, name: &str, v: f32) {
b45b8b4cf0f5 get rid of lazy_static, config is passed around
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
77 self.temps.insert(name.to_string(), v);
593
bf138339d20a fiddling with timeouts and closures
Matt Johnston <matt@ucc.asn.au>
parents: 592
diff changeset
78 }
bf138339d20a fiddling with timeouts and closures
Matt Johnston <matt@ucc.asn.au>
parents: 592
diff changeset
79
603
b45b8b4cf0f5 get rid of lazy_static, config is passed around
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
80 pub fn get_temp(&self, name: &str) -> Option<f32> {
b45b8b4cf0f5 get rid of lazy_static, config is passed around
Matt Johnston <matt@ucc.asn.au>
parents: 596
diff changeset
81 self.temps.get(name).map(|f| *f)
592
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
82 }
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
83 }
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
84
604
278f1002b5c7 sensor regex, custom error type
Matt Johnston <matt@ucc.asn.au>
parents: 603
diff changeset
85 #[derive(Debug)]
611
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
86 pub enum TemplogErrorKind {
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
87 None,
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
88 Io(io::Error),
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
89 ParseFloat(std::num::ParseFloatError),
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
90 TomlDe(toml::de::Error),
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
91 SerdeJson(serde_json::Error),
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
92 Curl(curl::Error),
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
93 }
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
94
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
95 #[derive(Debug)]
604
278f1002b5c7 sensor regex, custom error type
Matt Johnston <matt@ucc.asn.au>
parents: 603
diff changeset
96 pub struct TemplogError {
278f1002b5c7 sensor regex, custom error type
Matt Johnston <matt@ucc.asn.au>
parents: 603
diff changeset
97 desc: String,
611
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
98 kind: TemplogErrorKind,
604
278f1002b5c7 sensor regex, custom error type
Matt Johnston <matt@ucc.asn.au>
parents: 603
diff changeset
99 }
278f1002b5c7 sensor regex, custom error type
Matt Johnston <matt@ucc.asn.au>
parents: 603
diff changeset
100
278f1002b5c7 sensor regex, custom error type
Matt Johnston <matt@ucc.asn.au>
parents: 603
diff changeset
101 impl Error for TemplogError {
611
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
102 fn description(&self) -> &str {
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
103 &format!("{}", self)
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
104 }
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
105
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
106 fn cause(&self) -> Option<&Error> {
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
107 match self.kind {
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
108 TemplogErrorKind::None => None,
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
109 TemplogErrorKind::Io(e) => Some(&e),
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
110 TemplogErrorKind::ParseFloat(e) => Some(&e),
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
111 TemplogErrorKind::TomlDe(e) => Some(&e),
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
112 TemplogErrorKind::SerdeJson(e) => Some(&e),
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
113 TemplogErrorKind::Curl(e) => Some(&e),
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
114 }
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
115 }
604
278f1002b5c7 sensor regex, custom error type
Matt Johnston <matt@ucc.asn.au>
parents: 603
diff changeset
116 }
278f1002b5c7 sensor regex, custom error type
Matt Johnston <matt@ucc.asn.au>
parents: 603
diff changeset
117
278f1002b5c7 sensor regex, custom error type
Matt Johnston <matt@ucc.asn.au>
parents: 603
diff changeset
118 impl fmt::Display for TemplogError {
278f1002b5c7 sensor regex, custom error type
Matt Johnston <matt@ucc.asn.au>
parents: 603
diff changeset
119 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
611
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
120 match self.kind {
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
121 TemplogErrorKind::None => write!(f, "Templog Error: {}", self.desc),
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
122 TemplogErrorKind::Io(e) => write!(f, "Templog IO error {}: {}", self.desc, e),
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
123 TemplogErrorKind::TomlDe(e) => write!(f, "Templog toml error {}: {}", self.desc, e),
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
124 TemplogErrorKind::SerdeJson(e) => write!(f, "Json decode error {}: {}", self.desc, e),
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
125 TemplogErrorKind::ParseFloat(e) => write!(f, "Templog parse error {}: {}", self.desc, e),
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
126 TemplogErrorKind::Curl(e) => write!(f, "Templog curl http error {}: {}", self.desc, e),
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
127 };
604
278f1002b5c7 sensor regex, custom error type
Matt Johnston <matt@ucc.asn.au>
parents: 603
diff changeset
128 Ok(())
278f1002b5c7 sensor regex, custom error type
Matt Johnston <matt@ucc.asn.au>
parents: 603
diff changeset
129 }
278f1002b5c7 sensor regex, custom error type
Matt Johnston <matt@ucc.asn.au>
parents: 603
diff changeset
130 }
278f1002b5c7 sensor regex, custom error type
Matt Johnston <matt@ucc.asn.au>
parents: 603
diff changeset
131
278f1002b5c7 sensor regex, custom error type
Matt Johnston <matt@ucc.asn.au>
parents: 603
diff changeset
132 impl TemplogError {
278f1002b5c7 sensor regex, custom error type
Matt Johnston <matt@ucc.asn.au>
parents: 603
diff changeset
133 pub fn new(desc: &str) -> Self {
278f1002b5c7 sensor regex, custom error type
Matt Johnston <matt@ucc.asn.au>
parents: 603
diff changeset
134 TemplogError {
278f1002b5c7 sensor regex, custom error type
Matt Johnston <matt@ucc.asn.au>
parents: 603
diff changeset
135 desc: desc.to_string(),
611
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
136 kind: TemplogErrorKind::None,
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
137 }
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
138 }
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
139
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
140 pub fn new_io(desc: &str, e: io::Error) -> Self {
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
141 TemplogError {
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
142 desc: desc.to_string(),
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
143 kind: TemplogErrorKind::Io(e),
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
144 }
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
145 }
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
146
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
147 pub fn new_toml_de(desc: &str, e: toml::de::Error) -> Self {
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
148 TemplogError {
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
149 desc: desc.to_string(),
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
150 kind: TemplogErrorKind::TomlDe(e),
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
151 }
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
152 }
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
153
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
154 pub fn new_parse_float(desc: &str, e: std::num::ParseFloatError) -> Self {
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
155 TemplogError {
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
156 desc: desc.to_string(),
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
157 kind: TemplogErrorKind::ParseFloat(e),
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
158 }
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
159 }
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
160
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
161 pub fn new_curl(desc: &str, e: curl::Error) -> Self {
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
162 TemplogError {
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
163 desc: desc.to_string(),
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
164 kind: TemplogErrorKind::Curl(e),
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
165 }
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
166 }
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
167
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
168 pub fn new_serde_json(desc: &str, e: serde_json::Error) -> Self {
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
169 TemplogError {
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
170 desc: desc.to_string(),
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
171 kind: TemplogErrorKind::SerdeJson(e),
604
278f1002b5c7 sensor regex, custom error type
Matt Johnston <matt@ucc.asn.au>
parents: 603
diff changeset
172 }
278f1002b5c7 sensor regex, custom error type
Matt Johnston <matt@ucc.asn.au>
parents: 603
diff changeset
173 }
278f1002b5c7 sensor regex, custom error type
Matt Johnston <matt@ucc.asn.au>
parents: 603
diff changeset
174 }
278f1002b5c7 sensor regex, custom error type
Matt Johnston <matt@ucc.asn.au>
parents: 603
diff changeset
175
611
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
176 impl From<io::Error> for TemplogError {
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
177 fn from(e: io::Error) -> Self {
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
178 TemplogError::new_io("", e)
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
179 }
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
180 }
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
181
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
182 impl From<toml::de::Error> for TemplogError {
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
183 fn from(e: toml::de::Error) -> Self {
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
184 TemplogError::new_toml_de("", e)
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
185 }
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
186 }
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
187
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
188 impl From<std::num::ParseFloatError> for TemplogError {
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
189 fn from(e: std::num::ParseFloatError) -> Self {
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
190 TemplogError::new_parse_float("", e)
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
191 }
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
192 }
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
193
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
194 impl From<curl::Error> for TemplogError {
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
195 fn from(e: curl::Error) -> Self {
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
196 TemplogError::new_curl("", e)
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
197 }
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
198 }
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
199
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
200 impl From<serde_json::Error> for TemplogError {
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
201 fn from(e: serde_json::Error) -> Self {
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
202 TemplogError::new_serde_json("", e)
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
203 }
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
204 }
604
278f1002b5c7 sensor regex, custom error type
Matt Johnston <matt@ucc.asn.au>
parents: 603
diff changeset
205
609
7bda01659426 not building, paramwaiter work
Matt Johnston <matt@ucc.asn.au>
parents: 604
diff changeset
206 /// Call closures with a rate limit. Useful for log message ratelimiting
611
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
207 #[derive(Clone)]
609
7bda01659426 not building, paramwaiter work
Matt Johnston <matt@ucc.asn.au>
parents: 604
diff changeset
208 pub struct NotTooOften {
7bda01659426 not building, paramwaiter work
Matt Johnston <matt@ucc.asn.au>
parents: 604
diff changeset
209 last: Cell<Instant>,
7bda01659426 not building, paramwaiter work
Matt Johnston <matt@ucc.asn.au>
parents: 604
diff changeset
210 limit: Duration,
7bda01659426 not building, paramwaiter work
Matt Johnston <matt@ucc.asn.au>
parents: 604
diff changeset
211 }
604
278f1002b5c7 sensor regex, custom error type
Matt Johnston <matt@ucc.asn.au>
parents: 603
diff changeset
212
609
7bda01659426 not building, paramwaiter work
Matt Johnston <matt@ucc.asn.au>
parents: 604
diff changeset
213 impl NotTooOften {
7bda01659426 not building, paramwaiter work
Matt Johnston <matt@ucc.asn.au>
parents: 604
diff changeset
214 pub fn new(limit_secs: u64) -> Self {
7bda01659426 not building, paramwaiter work
Matt Johnston <matt@ucc.asn.au>
parents: 604
diff changeset
215 NotTooOften {
7bda01659426 not building, paramwaiter work
Matt Johnston <matt@ucc.asn.au>
parents: 604
diff changeset
216 limit: Duration::new(limit_secs, 0),
7bda01659426 not building, paramwaiter work
Matt Johnston <matt@ucc.asn.au>
parents: 604
diff changeset
217 last: Cell::new(Instant::now() - Duration::new(limit_secs+1, 0)),
7bda01659426 not building, paramwaiter work
Matt Johnston <matt@ucc.asn.au>
parents: 604
diff changeset
218 }
7bda01659426 not building, paramwaiter work
Matt Johnston <matt@ucc.asn.au>
parents: 604
diff changeset
219 }
7bda01659426 not building, paramwaiter work
Matt Johnston <matt@ucc.asn.au>
parents: 604
diff changeset
220
7bda01659426 not building, paramwaiter work
Matt Johnston <matt@ucc.asn.au>
parents: 604
diff changeset
221 pub fn and_then<F>(&self, op: F)
7bda01659426 not building, paramwaiter work
Matt Johnston <matt@ucc.asn.au>
parents: 604
diff changeset
222 where F: Fn() {
7bda01659426 not building, paramwaiter work
Matt Johnston <matt@ucc.asn.au>
parents: 604
diff changeset
223 let now = Instant::now();
7bda01659426 not building, paramwaiter work
Matt Johnston <matt@ucc.asn.au>
parents: 604
diff changeset
224 if now - self.last.get() > self.limit {
7bda01659426 not building, paramwaiter work
Matt Johnston <matt@ucc.asn.au>
parents: 604
diff changeset
225 self.last.set(now);
7bda01659426 not building, paramwaiter work
Matt Johnston <matt@ucc.asn.au>
parents: 604
diff changeset
226 op();
7bda01659426 not building, paramwaiter work
Matt Johnston <matt@ucc.asn.au>
parents: 604
diff changeset
227 }
7bda01659426 not building, paramwaiter work
Matt Johnston <matt@ucc.asn.au>
parents: 604
diff changeset
228 }
7bda01659426 not building, paramwaiter work
Matt Johnston <matt@ucc.asn.au>
parents: 604
diff changeset
229 }
7bda01659426 not building, paramwaiter work
Matt Johnston <matt@ucc.asn.au>
parents: 604
diff changeset
230
610
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
231 struct Period {
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
232 start: Instant,
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
233 end: Option<Instant>,
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
234 }
609
7bda01659426 not building, paramwaiter work
Matt Johnston <matt@ucc.asn.au>
parents: 604
diff changeset
235
610
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
236 pub struct StepIntegrator {
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
237 on_periods: Vec<Period>,
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
238 limit: Duration,
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
239 }
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
240
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
241 impl StepIntegrator {
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
242 pub fn new(limit: Duration) -> Self {
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
243 StepIntegrator {
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
244 on_periods: Vec::new(),
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
245 limit: limit,
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
246 }
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
247 }
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
248
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
249 pub fn turn(&mut self, on: bool) {
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
250 self.trim();
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
251
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
252 if self.on_periods.is_empty() {
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
253 self.on_periods.push( Period { start: Instant::now(), end: None });
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
254 return;
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
255 }
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
256
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
257 let current_on = self.on_periods.last().unwrap().end.is_none();
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
258 if on == current_on {
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
259 // state is unchanged
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
260 return;
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
261 }
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
262
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
263 if on {
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
264 self.on_periods.push( Period { start: Instant::now(), end: None });
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
265 } else {
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
266 self.on_periods.last_mut().unwrap().end = Some(Instant::now());
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
267 }
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
268 }
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
269
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
270 pub fn set_limit(&mut self, limit: Duration) {
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
271 self.limit = limit;
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
272 self.trim();
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
273 }
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
274
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
275 fn integrate(&self) -> Duration {
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
276 let durs = self.on_periods.iter().map(|p| {
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
277 let end = p.end.unwrap_or_else(|| Instant::now());
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
278 end - p.start
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
279 });
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
280 // TODO rust 1.16: impl Sum for Duration
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
281 // durs.sum()
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
282 durs.fold(Duration::new(0,0), |acc, d| acc + d)
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
283 }
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
284
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
285 fn trim(&mut self) {
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
286 let begin = Instant::now() - self.limit;
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
287
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
288 self.on_periods.retain(|p| {
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
289 // remove expired endtimes
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
290 if let Some(e) = p.end {
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
291 e >= begin && e != p.start
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
292 } else {
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
293 true
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
294 }
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
295 });
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
296
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
297 for p in &mut self.on_periods {
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
298 p.start = cmp::max(p.start, begin);
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
299 }
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
300 }
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
301 }
af0dac00d40b untested step integrator
Matt Johnston <matt@ucc.asn.au>
parents: 609
diff changeset
302
611
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
303 /// Takes a stream and returns a stream without errors.
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
304 pub fn consume_errors<S>(s: S) -> Box<Stream<Item=S::Item, Error=S::Error>>
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
305 // XXX not sure why 'static is really necessary here?
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
306 where
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
307 S: Stream+Send+'static,
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
308 <S as Stream>::Error: std::fmt::Display+Send+'static,
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
309 <S as Stream>::Item: Send+'static,
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
310 {
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
311 s.then(|r| {
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
312 match r {
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
313 Ok(v) => Ok(Some(v)),
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
314 Err(e) => {
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
315 debug!("Stream error: {}", e);
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
316 Ok(None)
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
317 }
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
318 }
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
319 })
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
320 .filter_map(|p| p).boxed()
f3e39e2107fd still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents: 610
diff changeset
321 }