1use std::fmt;
2
3#[derive(Debug)]
4#[non_exhaustive]
5pub enum Error {
6 Io(std::io::Error),
8 InvalidFormat(String),
10 Unsupported(String),
12}
13
14pub type Result<T> = std::result::Result<T, Error>;
15
16impl fmt::Display for Error {
17 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
18 match self {
19 Error::Io(e) => write!(f, "I/O error: {}", e),
20 Error::InvalidFormat(msg) => write!(f, "invalid format: {}", msg),
21 Error::Unsupported(msg) => write!(f, "unsupported: {}", msg),
22 }
23 }
24}
25
26impl std::error::Error for Error {
27 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
28 match self {
29 Error::Io(e) => Some(e),
30 _ => None,
31 }
32 }
33}
34
35impl From<std::io::Error> for Error {
36 fn from(e: std::io::Error) -> Self {
37 Error::Io(e)
38 }
39}