Better error handling (fixes #15)
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
use std::borrow::Cow;
|
||||
use std::collections::HashMap;
|
||||
use std::process::ExitStatus;
|
||||
|
||||
pub type Report = HashMap<String, bool>;
|
||||
|
||||
@@ -8,9 +7,30 @@ pub trait Reporter {
|
||||
fn report<'a, M: Into<Cow<'a, str>>>(&self, key: M, report: &mut Report);
|
||||
}
|
||||
|
||||
impl Reporter for ExitStatus {
|
||||
impl<T, E> Reporter for Result<T, E>
|
||||
where
|
||||
T: Reporter,
|
||||
{
|
||||
fn report<'a, M: Into<Cow<'a, str>>>(&self, key: M, report: &mut Report) {
|
||||
report.insert(key.into().into_owned(), self.success());
|
||||
match self {
|
||||
Err(_) => {
|
||||
report.insert(key.into().into_owned(), false);
|
||||
}
|
||||
Ok(item) => {
|
||||
item.report(key, report);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Reporter for Option<T>
|
||||
where
|
||||
T: Reporter,
|
||||
{
|
||||
fn report<'a, M: Into<Cow<'a, str>>>(&self, key: M, report: &mut Report) {
|
||||
if let Some(item) = self {
|
||||
item.report(key, report);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,3 +39,9 @@ impl Reporter for bool {
|
||||
report.insert(key.into().into_owned(), *self);
|
||||
}
|
||||
}
|
||||
|
||||
impl Reporter for () {
|
||||
fn report<'a, M: Into<Cow<'a, str>>>(&self, key: M, report: &mut Report) {
|
||||
report.insert(key.into().into_owned(), true);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user