1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use failure::Error;
pub fn to_failure<T, E: ToString>(x: Result<T, E>) -> Result<T, Error> {
match x {
Err(e) => Err(failure::format_err!("{}", e.to_string())),
Ok(s) => Ok(s),
}
}
pub fn to_io<T, E: ToString>(x: Result<T, E>, kind: std::io::ErrorKind) -> std::io::Result<T> {
match x {
Err(e) => Err(std::io::Error::new(kind, e.to_string())),
Ok(s) => Ok(s),
}
}
pub fn opt_to_failure<T>(x: Option<T>, s: &str) -> Result<T, Error> {
match x {
Some(s) => Ok(s),
None => Err(failure::format_err!("{}", s)),
}
}