1
use std::fmt::{Display, Formatter};
2
use std::io::Error;
3

            
4
#[derive(Debug)]
5
pub enum AetoliaError {
6
    IO(Error),
7

            
8
    Other(String),
9
}
10

            
11
impl From<Error> for AetoliaError {
12
    fn from(value: Error) -> Self {
13
        Self::IO(value)
14
    }
15
}
16

            
17
impl AetoliaError {
18
    pub fn time(e: impl Into<time::error::Error>) -> Self {
19
        AetoliaError::Other(e.into().to_string())
20
    }
21

            
22
24
    pub fn other(msg: impl ToString) -> AetoliaError {
23
24
        AetoliaError::Other(msg.to_string())
24
24
    }
25
}
26

            
27
impl Display for AetoliaError {
28
20
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
29
20
        match self {
30
            AetoliaError::IO(e) => e.fmt(f),
31
20
            AetoliaError::Other(msg) => write!(f, "{}", msg),
32
        }
33
20
    }
34
}
35

            
36
impl std::error::Error for AetoliaError {}
37

            
38
pub type AetoliaResult<T> = Result<T, AetoliaError>;