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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use std::fmt;
#[derive(Debug)]
pub enum ServerError {
HyperError(::hyper::Error),
FutureCancelledError(::futures::Canceled),
ParseError(::std::net::AddrParseError),
InvalidUri(crate::http_types::uri::InvalidUri),
UnsupportedUriScheme,
IOError(::std::io::Error),
BadListenerConfig,
}
impl From<::std::net::AddrParseError> for ServerError {
fn from(e: ::std::net::AddrParseError) -> Self {
ServerError::ParseError(e)
}
}
impl From<::hyper::Error> for ServerError {
fn from(e: ::hyper::Error) -> Self {
ServerError::HyperError(e)
}
}
impl From<::futures::Canceled> for ServerError {
fn from(e: ::futures::Canceled) -> Self {
ServerError::FutureCancelledError(e)
}
}
impl From<crate::http_types::uri::InvalidUri> for ServerError {
fn from(e: crate::http_types::uri::InvalidUri) -> Self {
ServerError::InvalidUri(e)
}
}
impl From<::std::io::Error> for ServerError {
fn from(e: ::std::io::Error) -> Self {
ServerError::IOError(e)
}
}
impl ::std::error::Error for ServerError {
fn description(&self) -> &str {
use crate::ServerError::*;
match self {
HyperError(ref e) => e.description(),
FutureCancelledError(ref e) => e.description(),
ParseError(ref e) => e.description(),
InvalidUri(ref e) => e.description(),
UnsupportedUriScheme => "Unsupported URI scheme",
IOError(ref e) => e.description(),
BadListenerConfig => "Bad listener configuration",
}
}
}
impl ::std::fmt::Display for ServerError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result<> {
use crate::ServerError::*;
match self {
HyperError(ref e) => e.fmt(f),
FutureCancelledError(ref e) => e.fmt(f),
ParseError(ref e) => e.fmt(f),
InvalidUri(ref e) => e.fmt(f),
UnsupportedUriScheme => write!(f, "Unsupported URI scheme"),
IOError(ref e) => e.fmt(f),
BadListenerConfig => write!(f, "Bad listener configuration"),
}
}
}