1use std::fmt;
2use std;
3
4pub type WebSocketResult<T> = Result<T, WebSocketError>;
6
7#[derive(Debug, PartialEq)]
9pub enum WebSocketError {
10 UnreachableHost,
11 HandShake,
12 InvalidFrame,
13 ConnectionClose,
14 DecodingFromUTF8,
15 IOError,
16}
17
18impl fmt::Display for WebSocketError {
29 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
30 fmt.write_str("WebSocketError: ")?;
31 match self {
32 WebSocketError::UnreachableHost => fmt.write_str("Unreachable host"),
33 WebSocketError::HandShake => fmt.write_str("Error performing initial handshake"),
34 WebSocketError::InvalidFrame => fmt.write_str("Invalid frame received"),
35 WebSocketError::ConnectionClose => fmt.write_str("The connection was closed"),
36 WebSocketError::DecodingFromUTF8 => fmt.write_str("Error decoding from utf8"),
37 WebSocketError::IOError => fmt.write_str("IOError")
38 }
39 }
40}
41
42impl From<std::io::Error> for WebSocketError {
43 fn from(_: std::io::Error) -> Self {
44 WebSocketError::IOError
45 }
46}