use std::error::Error;
use std::fmt::{Display, Formatter, Result};
use std::io::Error as IoError;
#[derive(Debug)]
pub struct AppError {
cause: Option<Box<dyn Error>>,
details: String,
}
impl AppError {
pub fn new(cause: Option<Box<dyn Error>>, details: String) -> Self {
Self {
cause,
details,
}
}
}
impl Display for AppError {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
write!(f, "{}", self.details)
}
}
impl Error for AppError {}
impl From<IoError> for AppError {
fn from(error: IoError) -> Self {
AppError::new(Some(Box::new(error)), String::from("Found std::io::Error"))
}
}