Add type MatchError
This commit is contained in:
parent
e6fb2f232d
commit
96ca9637d1
1 changed files with 48 additions and 0 deletions
|
@ -1,3 +1,7 @@
|
|||
use std::error::Error;
|
||||
use std::fmt::{Debug, Display, Formatter};
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum FileHeaderSpec {
|
||||
Null,
|
||||
|
@ -27,3 +31,47 @@ pub trait FileData : Sized {
|
|||
fn get_abbrev(&self) -> String;
|
||||
}
|
||||
|
||||
pub struct MatchError {
|
||||
summary: String,
|
||||
path: Vec<FileHeaderSpec>,
|
||||
expected: FileHeaderSpec,
|
||||
found: FileHeaderSpec
|
||||
}
|
||||
|
||||
impl MatchError {
|
||||
pub fn format(&self) -> String {
|
||||
format!("MatchError: {:?}\n\nHaving: {:?}\nExpected: {:?}\nFound: {:?}\n",
|
||||
self.summary, self.path, self.expected, self.found)
|
||||
}
|
||||
}
|
||||
|
||||
impl Error for MatchError {
|
||||
|
||||
fn description(&self) -> &str {
|
||||
&self.summary[..]
|
||||
}
|
||||
|
||||
fn cause(&self) -> Option<&Error> {
|
||||
None
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl Debug for MatchError {
|
||||
|
||||
fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
|
||||
write!(fmt, "{}", self.format());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl Display for MatchError {
|
||||
|
||||
fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
|
||||
write!(fmt, "{}", self.format());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue