use std::fmt;
use std::fmt::Display;
use std::io;
#[cfg(test)]
#[path = "./error_test.rs"]
mod error_test;
#[derive(Debug)]
pub enum ErrorInfo {
PathAlreadyExists(String),
NotFile(String),
IOError(String, Option<io::Error>),
}
#[derive(Debug)]
pub struct FsIOError {
pub info: ErrorInfo,
}
impl Display for FsIOError {
fn fmt(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> {
match self.info {
ErrorInfo::PathAlreadyExists(ref message) => write!(formatter, "{}", message),
ErrorInfo::NotFile(ref message) => write!(formatter, "{}", message),
ErrorInfo::IOError(ref message, ref cause) => {
writeln!(formatter, "{}", message)?;
match cause {
Some(cause_err) => cause_err.fmt(formatter),
None => Ok(()),
}
}
}
}
}