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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// depura::error
//
//! Error types.
//

use log::{ParseLevelError, SetLoggerError};
#[cfg(feature = "std")]
use time::error::InvalidFormatDescription;

/// The *depura* result type.
pub type DepuraResult<N> = core::result::Result<N, DepuraError>;

/// The *depura* error type.
#[non_exhaustive]
pub enum DepuraError {
    /* from the log crate*/
    SetLogger(SetLoggerError),
    ParseLevel(ParseLevelError),

    /* from the time crate */
    #[cfg(feature = "std")]
    #[cfg_attr(feature = "nightly", doc(cfg(feature = "std")))]
    InvalidFormatDescription(InvalidFormatDescription),

    /// There are no loggers configured.
    NoLoggers,
}

mod core_impls {
    use super::*;
    use core::fmt;

    impl fmt::Display for DepuraError {
        fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
            use DepuraError::*;
            match self {
                #[cfg(feature = "std")]
                InvalidFormatDescription(i) => {
                    write!(f, "DepuraError::InvalidFormatDescription({i})")
                }
                SetLogger(_) => write!(f, "DepuraError::SetLogger(SetLoggerError)"),
                ParseLevel(_) => write!(f, "DepuraError::ParseLevel(ParseLevelError)"),
                NoLoggers => write!(f, "DepuraError::NoLoggers"),
                // _ => write!(f, ""),
            }
        }
    }
    impl fmt::Debug for DepuraError {
        fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
            fmt::Display::fmt(self, f)
        }
    }

    impl From<SetLoggerError> for DepuraError {
        fn from(err: SetLoggerError) -> Self {
            DepuraError::SetLogger(err)
        }
    }
    impl From<ParseLevelError> for DepuraError {
        fn from(err: ParseLevelError) -> Self {
            DepuraError::ParseLevel(err)
        }
    }
    #[cfg(feature = "std")]
    #[cfg_attr(feature = "nightly", doc(cfg(feature = "std")))]
    impl From<InvalidFormatDescription> for DepuraError {
        fn from(err: InvalidFormatDescription) -> Self {
            DepuraError::InvalidFormatDescription(err)
        }
    }
}

#[cfg(feature = "std")]
mod std_impls {
    use super::DepuraError;

    #[cfg_attr(feature = "nightly", doc(cfg(feature = "std")))]
    impl std::error::Error for DepuraError {}
}