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
use std::fmt::{Display, Formatter};
use std::net::AddrParseError;
use std::string::FromUtf8Error;
#[derive(Debug, Eq, PartialEq, Clone)]
pub struct Error {
pub kind: std::io::ErrorKind,
pub message: String,
}
impl Display for Error {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?} , {}", self.kind, self.message)
}
}
impl std::error::Error for Error {}
impl From<std::io::Error> for Error {
fn from(e: std::io::Error) -> Self {
Error {
kind: e.kind(),
message: e.to_string(),
}
}
}
impl From<AddrParseError> for Error {
fn from(e: AddrParseError) -> Self {
Error {
kind: std::io::ErrorKind::AddrNotAvailable,
message: e.to_string(),
}
}
}
impl From<FromUtf8Error> for Error {
fn from(e: FromUtf8Error) -> Self {
Error {
kind: std::io::ErrorKind::Other,
message: e.to_string(),
}
}
}
impl Error {
pub fn new(kind: std::io::ErrorKind, message: String) -> Self {
Error { kind, message }
}
}