easy_http_proxy_server/
error.rs1use std::fmt;
4
5#[derive(Debug)]
7pub enum ProxyError {
8 Io(std::io::Error),
10 Hyper(hyper::Error),
12 AddressParse(std::net::AddrParseError),
14 Other(String),
16}
17
18impl fmt::Display for ProxyError {
19 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
20 match self {
21 ProxyError::Io(e) => write!(f, "IO error: {}", e),
22 ProxyError::Hyper(e) => write!(f, "Hyper error: {}", e),
23 ProxyError::AddressParse(e) => write!(f, "Address parse error: {}", e),
24 ProxyError::Other(e) => write!(f, "Error: {}", e),
25 }
26 }
27}
28
29impl std::error::Error for ProxyError {}
30
31impl From<std::io::Error> for ProxyError {
32 fn from(error: std::io::Error) -> Self {
33 ProxyError::Io(error)
34 }
35}
36
37impl From<hyper::Error> for ProxyError {
38 fn from(error: hyper::Error) -> Self {
39 ProxyError::Hyper(error)
40 }
41}
42
43impl From<std::net::AddrParseError> for ProxyError {
44 fn from(error: std::net::AddrParseError) -> Self {
45 ProxyError::AddressParse(error)
46 }
47}
48
49impl From<&str> for ProxyError {
50 fn from(error: &str) -> Self {
51 ProxyError::Other(error.to_string())
52 }
53}