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
42
43
44
45
46
47
48
49
50
use std::error::Error;
use std::fmt;
#[derive(Debug, PartialEq)]
pub struct LibwgetjError {
desc: String,
detail: String,
}
impl LibwgetjError {
pub fn new<T: fmt::Display>(desc: &str, detail: T) -> LibwgetjError
where T: fmt::Debug
{
LibwgetjError {
desc: desc.to_owned(),
detail: format!("{}", detail),
}
}
}
impl fmt::Display for LibwgetjError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
writeln!(f, "{}: {}", self.desc, self.detail)
}
}
impl Error for LibwgetjError {
fn description(&self) -> &str {
&self.desc
}
}
impl From<::std::io::Error> for LibwgetjError {
fn from(e: ::std::io::Error) -> LibwgetjError {
LibwgetjError::new("IO Error", e)
}
}