1use std::{fmt::Display, io};
2
3#[derive(Debug)]
4pub enum Error {
5 IO(io::Error),
6 Message(String),
7}
8
9impl std::error::Error for Error {}
10
11impl Display for Error {
12 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
13 match self {
14 Error::IO(err) => err.fmt(f),
15 Error::Message(err) => err.fmt(f),
16 }
17 }
18}
19
20impl Error {
21 pub fn other<S: Display>(err: S) -> Self {
22 Error::Message(err.to_string())
23 }
24}
25
26impl<T> From<T> for Error
27where
28 io::Error: From<T>,
29{
30 fn from(err: T) -> Self {
31 Error::IO(From::from(err))
32 }
33}