2018-06-03 18:04:58 +03:00
|
|
|
use std::borrow::Cow;
|
|
|
|
|
|
2018-06-27 18:06:24 +03:00
|
|
|
type CowString<'a> = Cow<'a, str>;
|
|
|
|
|
pub type Report<'a> = Vec<(CowString<'a>, bool)>;
|
2018-06-03 18:04:58 +03:00
|
|
|
|
|
|
|
|
pub trait Reporter {
|
2018-06-27 18:06:24 +03:00
|
|
|
fn report<'a, M: Into<CowString<'a>>>(&self, key: M, report: &mut Report<'a>);
|
2018-06-03 18:04:58 +03:00
|
|
|
}
|
|
|
|
|
|
2018-06-06 15:32:38 +03:00
|
|
|
impl<T, E> Reporter for Result<T, E>
|
|
|
|
|
where
|
|
|
|
|
T: Reporter,
|
|
|
|
|
{
|
2018-06-27 18:06:24 +03:00
|
|
|
fn report<'a, M: Into<CowString<'a>>>(&self, key: M, report: &mut Report<'a>) {
|
2018-06-06 15:32:38 +03:00
|
|
|
match self {
|
|
|
|
|
Err(_) => {
|
2018-06-27 18:06:24 +03:00
|
|
|
report.push((key.into(), false));
|
2018-06-06 15:32:38 +03:00
|
|
|
}
|
|
|
|
|
Ok(item) => {
|
|
|
|
|
item.report(key, report);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T> Reporter for Option<T>
|
|
|
|
|
where
|
|
|
|
|
T: Reporter,
|
|
|
|
|
{
|
2018-06-27 18:06:24 +03:00
|
|
|
fn report<'a, M: Into<CowString<'a>>>(&self, key: M, report: &mut Report<'a>) {
|
2018-06-06 15:32:38 +03:00
|
|
|
if let Some(item) = self {
|
|
|
|
|
item.report(key, report);
|
|
|
|
|
}
|
2018-06-03 18:04:58 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Reporter for bool {
|
2018-06-27 18:06:24 +03:00
|
|
|
fn report<'a, M: Into<CowString<'a>>>(&self, key: M, report: &mut Report<'a>) {
|
|
|
|
|
report.push((key.into(), *self));
|
2018-06-03 18:04:58 +03:00
|
|
|
}
|
|
|
|
|
}
|
2018-06-06 15:32:38 +03:00
|
|
|
|
|
|
|
|
impl Reporter for () {
|
2018-06-27 18:06:24 +03:00
|
|
|
fn report<'a, M: Into<CowString<'a>>>(&self, key: M, report: &mut Report<'a>) {
|
|
|
|
|
report.push((key.into(), true));
|
2018-06-06 15:32:38 +03:00
|
|
|
}
|
|
|
|
|
}
|