Files
topgrade/src/report.rs

48 lines
1.1 KiB
Rust
Raw Normal View History

2018-06-03 18:04:58 +03:00
use std::borrow::Cow;
use std::collections::HashMap;
pub type Report = HashMap<String, bool>;
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(_) => {
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);
}
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) {
report.insert(key.into().into_owned(), *self);
}
}
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) {
report.insert(key.into().into_owned(), true);
}
}