qq_bot/errors/
mod.rs

1#[derive(Debug)]
2pub enum QQError {
3    UnknownError,
4    IOError(std::io::Error),
5    NetError(String),
6}
7
8pub type QQResult<T = ()> = Result<T, QQError>;
9
10impl From<std::io::Error> for QQError {
11    fn from(e: std::io::Error) -> Self {
12        Self::IOError(e)
13    }
14}
15
16impl From<toml::de::Error> for QQError {
17    fn from(_: toml::de::Error) -> Self {
18        Self::UnknownError
19    }
20}
21
22impl From<url::ParseError> for QQError {
23    fn from(_: url::ParseError) -> Self {
24        Self::UnknownError
25    }
26}
27
28impl From<reqwest::Error> for QQError {
29    fn from(e: reqwest::Error) -> Self {
30        Self::NetError(e.to_string())
31    }
32}
33impl From<tokio_tungstenite::tungstenite::Error> for QQError {
34    fn from(e: tokio_tungstenite::tungstenite::Error) -> Self {
35        Self::NetError(e.to_string())
36    }
37}
38
39impl From<serde_json::Error> for QQError {
40    fn from(e: serde_json::Error) -> Self {
41        Self::NetError(e.to_string())
42    }
43}