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
use async_tungstenite::tungstenite;
use rmp_serde::{encode, decode};
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug)]
pub enum Error {
Tungstenite(tungstenite::Error),
Encode(encode::Error),
Decode(decode::Error),
Server { code: i32, message: Option<String> },
Custom(String),
}
impl Error {
pub fn custom(s: &str) -> Self { Self::Custom(s.to_owned()) }
}
impl From<tungstenite::Error> for Error {
fn from(e: tungstenite::Error) -> Self { Self::Tungstenite(e) }
}
impl From<encode::Error> for Error {
fn from(e: encode::Error) -> Self { Self::Encode(e) }
}
impl From<decode::Error> for Error {
fn from(e: decode::Error) -> Self { Self::Decode(e) }
}