milston/error/
mod.rs

1use std::{fmt::Display, io};
2
3pub type Result<T> = std::result::Result<T, Error>;
4
5#[derive(Debug)]
6pub enum Error {
7    Io(io::Error),
8    #[cfg(feature = "http")]
9    Http(reqwest::Error),
10    Serde(serde_json::Error),
11}
12
13impl Display for Error {
14    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
15        match self {
16            Self::Io(error) => write!(f, "{}", error),
17            #[cfg(feature = "http")]
18            Self::Http(error) => write!(f, "{}", error),
19            Self::Serde(error) => write!(f, "{}", error),
20        }
21    }
22}
23
24impl From<io::Error> for Error {
25    fn from(err: io::Error) -> Self {
26        Self::Io(err)
27    }
28}
29
30#[cfg(feature = "http")]
31impl From<reqwest::Error> for Error {
32    fn from(err: reqwest::Error) -> Self {
33        Self::Http(err)
34    }
35}
36
37impl From<serde_json::Error> for Error {
38    fn from(err: serde_json::Error) -> Self {
39        Self::Serde(err)
40    }
41}