1use log::{ParseLevelError, SetLoggerError};
7#[cfg(feature = "std")]
8use time::error::InvalidFormatDescription;
9
10pub type DepuraResult<N> = core::result::Result<N, DepuraError>;
12
13#[non_exhaustive]
15pub enum DepuraError {
16 SetLogger(SetLoggerError),
18 ParseLevel(ParseLevelError),
19
20 #[cfg(feature = "std")]
22 #[cfg_attr(feature = "nightly", doc(cfg(feature = "std")))]
23 InvalidFormatDescription(InvalidFormatDescription),
24
25 NoLoggers,
27}
28
29mod core_impls {
30 use super::*;
31 use core::fmt;
32
33 impl fmt::Display for DepuraError {
34 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
35 use DepuraError::*;
36 match self {
37 #[cfg(feature = "std")]
38 InvalidFormatDescription(i) => {
39 write!(f, "DepuraError::InvalidFormatDescription({i})")
40 }
41 SetLogger(_) => write!(f, "DepuraError::SetLogger(SetLoggerError)"),
42 ParseLevel(_) => write!(f, "DepuraError::ParseLevel(ParseLevelError)"),
43 NoLoggers => write!(f, "DepuraError::NoLoggers"),
44 }
46 }
47 }
48 impl fmt::Debug for DepuraError {
49 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
50 fmt::Display::fmt(self, f)
51 }
52 }
53
54 impl From<SetLoggerError> for DepuraError {
55 fn from(err: SetLoggerError) -> Self {
56 DepuraError::SetLogger(err)
57 }
58 }
59 impl From<ParseLevelError> for DepuraError {
60 fn from(err: ParseLevelError) -> Self {
61 DepuraError::ParseLevel(err)
62 }
63 }
64 #[cfg(feature = "std")]
65 #[cfg_attr(feature = "nightly", doc(cfg(feature = "std")))]
66 impl From<InvalidFormatDescription> for DepuraError {
67 fn from(err: InvalidFormatDescription) -> Self {
68 DepuraError::InvalidFormatDescription(err)
69 }
70 }
71}
72
73#[cfg(feature = "std")]
74mod std_impls {
75 use super::DepuraError;
76
77 #[cfg_attr(feature = "nightly", doc(cfg(feature = "std")))]
78 impl std::error::Error for DepuraError {}
79}