2018-06-03 18:04:58 +03:00
|
|
|
use std::borrow::Cow;
|
|
|
|
|
|
2018-06-11 08:32:45 +03:00
|
|
|
pub type Report = Vec<(String, bool)>;
|
2018-06-03 18:04:58 +03:00
|
|
|
|
|
|
|
|
pub trait Reporter {
|
|
|
|
|
fn report<'a, M: Into<Cow<'a, str>>>(&self, key: M, report: &mut Report);
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-06 15:32:38 +03:00
|
|
|
impl<T, E> Reporter for Result<T, E>
|
|
|
|
|
where
|
|
|
|
|
T: Reporter,
|
|
|
|
|
{
|
2018-06-03 18:04:58 +03:00
|
|
|
fn report<'a, M: Into<Cow<'a, str>>>(&self, key: M, report: &mut Report) {
|
2018-06-06 15:32:38 +03:00
|
|
|
match self {
|
|
|
|
|
Err(_) => {
|
2018-06-11 08:32:45 +03:00
|
|
|
report.push((key.into().into_owned(), false));
|
2018-06-06 15:32:38 +03:00
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
}
|
2018-06-03 18:04:58 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Reporter for bool {
|
|
|
|
|
fn report<'a, M: Into<Cow<'a, str>>>(&self, key: M, report: &mut Report) {
|
2018-06-11 08:32:45 +03:00
|
|
|
report.push((key.into().into_owned(), *self));
|
2018-06-03 18:04:58 +03:00
|
|
|
}
|
|
|
|
|
}
|
2018-06-06 15:32:38 +03:00
|
|
|
|
|
|
|
|
impl Reporter for () {
|
|
|
|
|
fn report<'a, M: Into<Cow<'a, str>>>(&self, key: M, report: &mut Report) {
|
2018-06-11 08:32:45 +03:00
|
|
|
report.push((key.into().into_owned(), true));
|
2018-06-06 15:32:38 +03:00
|
|
|
}
|
|
|
|
|
}
|