wthr/
error.rs

1pub type Result<T> = std::result::Result<T, Error>;
2
3pub fn err<T>(message: &str) -> Result<T> {
4    Err(Error::Internal(message.to_string()))
5}
6
7#[derive(Debug)]
8pub enum Error {
9    ColorGrad(colorgrad::CustomGradientError),
10    Internal(String),
11    Reqwest(reqwest::Error),
12    Rusqlite(rusqlite::Error),
13    Serde(serde_json::error::Error),
14    StdIo(std::io::Error),
15    Toml(toml::de::Error),
16}
17
18impl From<reqwest::Error> for Error {
19    fn from(error: reqwest::Error) -> Self {
20        Error::Reqwest(error)
21    }
22}
23
24impl From<serde_json::error::Error> for Error {
25    fn from(error: serde_json::error::Error) -> Self {
26        Error::Serde(error)
27    }
28}
29
30impl From<rusqlite::Error> for Error {
31    fn from(error: rusqlite::Error) -> Self {
32        Error::Rusqlite(error)
33    }
34}
35
36impl From<std::io::Error> for Error {
37    fn from(error: std::io::Error) -> Self {
38        Error::StdIo(error)
39    }
40}
41
42impl From<colorgrad::CustomGradientError> for Error {
43    fn from(error: colorgrad::CustomGradientError) -> Self {
44        Error::ColorGrad(error)
45    }
46}
47
48impl From<toml::de::Error> for Error {
49    fn from(error: toml::de::Error) -> Self {
50        Error::Toml(error)
51    }
52}