1use std::{error, fmt, io};
4
5#[derive(Debug)]
7pub enum Error {
8 Unsupported,
10 Io(io::Error),
12 Other(Box<dyn error::Error + Send + Sync + 'static>),
14}
15
16impl fmt::Display for Error {
17 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
18 match self {
19 Error::Unsupported => f.write_str("unsupported"),
20 Error::Io(e) => fmt::Display::fmt(e, f),
21 Error::Other(e) => fmt::Display::fmt(e, f),
22 }
23 }
24}
25
26impl error::Error for Error {
27 fn source(&self) -> Option<&(dyn error::Error + 'static)> {
28 match self {
29 Error::Io(e) => Some(e),
30 Error::Other(e) => Some(&**e),
31 _ => None,
32 }
33 }
34}
35
36impl From<io::Error> for Error {
37 fn from(e: io::Error) -> Self {
38 Error::Io(e)
39 }
40}
41
42impl From<&'static str> for Error {
43 fn from(e: &'static str) -> Self {
44 Error::Other(e.into())
45 }
46}