#[cfg(test)]
#[path = "./errors_test.rs"]
mod errors_test;
use std::error::Error;
use std::fmt;
use std::fmt::Display;
#[derive(Debug, Copy, Clone)]
pub enum ErrorKind {
FileNotFound(&'static str),
FileOpen(&'static str),
}
#[derive(Debug, Copy, Clone)]
pub struct EnvmntError {
pub kind: ErrorKind,
}
impl Error for EnvmntError {
fn description(&self) -> &str {
match self.kind {
ErrorKind::FileNotFound(description) => description,
ErrorKind::FileOpen(description) => description,
}
}
}
impl Display for EnvmntError {
fn fmt(&self, format: &mut fmt::Formatter) -> Result<(), fmt::Error> {
match self.kind {
ErrorKind::FileNotFound(ref file) => file.fmt(format),
ErrorKind::FileOpen(ref file) => file.fmt(format),
}
}
}
impl EnvmntError {
pub fn is_file_not_found(&self) -> bool {
match self.kind {
ErrorKind::FileNotFound(_) => true,
_ => false,
}
}
pub fn is_file_open(&self) -> bool {
match self.kind {
ErrorKind::FileOpen(_) => true,
_ => false,
}
}
}