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
51
52
53
54
55
56
57
58
59
60
use failure::{Backtrace, Fail};
use std::fmt;
use std::io;
#[derive(Debug, Fail)]
pub enum NetIOErrorValue {
#[fail(display = "not enough bytes")]
NotEnoughBytes,
#[fail(display = "empty stream")]
EmptyStream,
#[fail(display = "io error\n")]
IOError(io::Error),
#[fail(display = "time out error\n")]
TimeoutError,
#[fail(display = "none return")]
NoneReturn,
}
#[derive(Debug)]
pub struct NetIOError {
pub value: NetIOErrorValue,
}
impl From<NetIOErrorValue> for NetIOError {
fn from(val: NetIOErrorValue) -> Self {
NetIOError { value: val }
}
}
impl From<io::Error> for NetIOError {
fn from(error: io::Error) -> Self {
NetIOError {
value: NetIOErrorValue::IOError(error),
}
}
}
impl fmt::Display for NetIOError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(&self.value, f)
}
}
impl Fail for NetIOError {
fn cause(&self) -> Option<&dyn Fail> {
self.value.cause()
}
fn backtrace(&self) -> Option<&Backtrace> {
self.value.backtrace()
}
}