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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
use crate::{ import::*, CloseEvent };
#[ derive( Debug ) ]
pub struct WsErr
{
inner: FailContext<WsErrKind>,
}
#[ derive( Clone, PartialEq, Eq, Debug, Fail ) ]
pub enum WsErrKind
{
#[ fail( display = "Invalid input to conversion to WsReadyState: {}", _0 ) ]
InvalidWsState( u16 ),
#[ fail( display = "The connection state is not \"Open\"" ) ]
ConnectionNotOpen,
#[ fail( display = "The port to which the connection is being attempted is not allowed." ) ]
ForbiddenPort,
#[ fail( display = "An invalid url was given to the connect method: {}", _0 ) ]
InvalidUrl(String),
#[ fail( display = "An invalid close code was given to a close method: {}", _0 ) ]
InvalidCloseCode(u16),
#[ fail( display = "The reason string given to a close method is to long." ) ]
ReasonStringToLong,
#[ fail( display = "Failed to connect to the server. CloseEvent: {:?}", _0 ) ]
ConnectionFailed(CloseEvent),
}
impl Fail for WsErr
{
fn cause( &self ) -> Option< &dyn Fail >
{
self.inner.cause()
}
fn backtrace( &self ) -> Option< &Backtrace >
{
self.inner.backtrace()
}
}
impl fmt::Display for WsErr
{
fn fmt( &self, f: &mut fmt::Formatter<'_> ) -> fmt::Result
{
fmt::Display::fmt( &self.inner, f )
}
}
impl WsErr
{
pub fn kind( &self ) -> &WsErrKind
{
self.inner.get_context()
}
}
impl From<WsErrKind> for WsErr
{
fn from( kind: WsErrKind ) -> WsErr
{
WsErr { inner: FailContext::new( kind ) }
}
}
impl From< FailContext<WsErrKind> > for WsErr
{
fn from( inner: FailContext<WsErrKind> ) -> WsErr
{
WsErr { inner }
}
}