1use std::{fmt, io};
2
3#[derive(Debug)]
4pub enum Error {
5 IO(io::Error),
6 Internal(String)
7}
8
9#[allow(clippy::needless_pass_by_value)]
10impl Error {
11 pub fn internal(s: impl ToString) -> Self {
12 Self::Internal(s.to_string())
13 }
14}
15
16impl std::error::Error for Error {}
17
18impl From<io::Error> for Error {
19 fn from(err: io::Error) -> Self {
20 Self::IO(err)
21 }
22}
23
24impl fmt::Display for Error {
25 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
26 match self {
27 Self::IO(e) => write!(f, "I/O error; {e}"),
28 Self::Internal(e) => write!(f, "Internal error; {e}")
29 }
30 }
31}
32
33