Implement the Error trait on the Error enum

This commit is contained in:
Oliver Hamlet
2018-10-06 16:04:57 +01:00
parent 594c8d19af
commit 04a92f9968
+26
View File
@@ -12,6 +12,7 @@ mod function;
mod version;
use std::collections::{HashMap, HashSet};
use std::error;
use std::ffi::OsStr;
use std::fmt;
use std::io;
@@ -46,6 +47,31 @@ impl From<io::Error> for Error {
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Error::ParsingIncomplete => write!(f, "More input was expected by the parser"),
Error::ParsingError => {
write!(f, "An error was encountered while parsing the expression")
}
Error::PeParsingError => write!(
f,
"An error was encountered while reading the version of an executable"
),
Error::IoError(e) => e.fmt(f),
}
}
}
impl error::Error for Error {
fn cause(&self) -> Option<&error::Error> {
match self {
Error::IoError(e) => Some(e),
_ => None,
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum GameType {
Tes4,