1use log::SetLoggerError;
2use std::{borrow::Cow, fmt, io};
3
4#[derive(Debug)]
5pub enum Error {
6 Io(io::Error),
7 Log(SetLoggerError),
8 Desc(Cow<'static, str>),
9}
10
11impl fmt::Display for Error {
12 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
13 match self {
14 Error::Io(io) => write!(fmt, "{}", io),
15 Error::Log(log) => write!(fmt, "{}", log),
16 Error::Desc(desc) => write!(fmt, "{}", desc.as_ref()),
17 }
18 }
19}
20
21impl std::error::Error for Error {
22 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
23 match self {
24 Error::Io(io) => io.source(),
25 Error::Log(_) => None,
26 Error::Desc(_) => None,
27 }
28 }
29}
30
31impl From<io::Error> for Error {
32 fn from(e: io::Error) -> Self {
33 Error::Io(e)
34 }
35}
36
37impl From<SetLoggerError> for Error {
38 fn from(e: SetLoggerError) -> Self {
39 Error::Log(e)
40 }
41}
42
43impl From<&'static str> for Error {
44 fn from(str: &'static str) -> Self {
45 Error::Desc(str.into())
46 }
47}
48
49impl From<String> for Error {
50 fn from(str: String) -> Self {
51 Error::Desc(str.into())
52 }
53}
54
55impl From<Cow<'static, str>> for Error {
56 fn from(str: Cow<'static, str>) -> Self {
57 Error::Desc(str)
58 }
59}