comparison rust/src/types.rs @ 633:490e9e15b98c rust

move some bits to riker
author Matt Johnston <matt@ucc.asn.au>
date Wed, 04 Sep 2019 23:24:13 +0800
parents efcbe0d3afd6
children a5721c02d3ee
comparison
equal deleted inserted replaced
632:bde302def78e 633:490e9e15b98c
3 use std::error::Error; 3 use std::error::Error;
4 use std::fmt; 4 use std::fmt;
5 use std::io; 5 use std::io;
6 use std::cmp; 6 use std::cmp;
7 use std::cell::Cell; 7 use std::cell::Cell;
8 use std::iter::FromIterator; 8
9 use std; 9 use std;
10 10
11 use futures::{Stream,IntoFuture};
12 use serde::{Deserialize,Serialize}; 11 use serde::{Deserialize,Serialize};
13 use toml; 12 use toml;
14 use hyper; 13 use hyper;
15 use serde_json; 14 use serde_json;
16 15
55 impl Error for TemplogError { 54 impl Error for TemplogError {
56 fn description(&self) -> &str { 55 fn description(&self) -> &str {
57 &self.desc 56 &self.desc
58 } 57 }
59 58
60 fn cause(&self) -> Option<&Error> { 59 fn cause(&self) -> Option<&dyn Error> {
61 match self.kind { 60 match self.kind {
62 TemplogErrorKind::None => None, 61 TemplogErrorKind::None => None,
63 TemplogErrorKind::Io(ref e) => Some(e), 62 TemplogErrorKind::Io(ref e) => Some(e),
64 TemplogErrorKind::ParseFloat(ref e) => Some(e), 63 TemplogErrorKind::ParseFloat(ref e) => Some(e),
65 TemplogErrorKind::TomlDe(ref e) => Some(e), 64 TemplogErrorKind::TomlDe(ref e) => Some(e),
266 p.start = cmp::max(p.start, begin); 265 p.start = cmp::max(p.start, begin);
267 } 266 }
268 } 267 }
269 } 268 }
270 269
271 /// Takes a stream and returns a stream without errors.
272 pub fn consume_errors<S>(s: S) -> Box<Stream<Item=S::Item, Error=S::Error>>
273 where
274 S: Stream+Send+'static,
275 <S as Stream>::Error: std::fmt::Display+Send+'static,
276 <S as Stream>::Item: Send+'static,
277 {
278 let f = s.then(|r| {
279 match r {
280 Ok(v) => Ok(Some(v)),
281 Err(e) => {
282 debug!("Stream error: {}", e);
283 Ok(None)
284 }
285 }
286 })
287 .filter_map(|p| p);
288 Box::new(f)
289 }