1use std::fmt;
4use std::io;
5
6pub type Result<T> = core::result::Result<T, Error>;
8
9#[derive(Debug)]
11pub enum Error {
12 Io(io::Error),
14 Format(fmt::Error),
17 Configuration(&'static str),
19}
20
21impl fmt::Display for Error {
22 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23 match self {
24 Self::Io(e) => write!(f, "io error: {e}"),
25 Self::Format(e) => write!(f, "format error: {e}"),
26 Self::Configuration(msg) => write!(f, "configuration error: {msg}"),
27 }
28 }
29}
30
31impl std::error::Error for Error {
32 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
33 match self {
34 Self::Io(e) => Some(e),
35 Self::Format(e) => Some(e),
36 Self::Configuration(_) => None,
37 }
38 }
39}
40
41impl From<io::Error> for Error {
42 fn from(value: io::Error) -> Self {
43 Self::Io(value)
44 }
45}
46
47impl From<fmt::Error> for Error {
48 fn from(value: fmt::Error) -> Self {
49 Self::Format(value)
50 }
51}