use std::borrow::Cow; use std::collections::HashMap; pub type Report = HashMap; pub trait Reporter { fn report<'a, M: Into>>(&self, key: M, report: &mut Report); } impl Reporter for Result where T: Reporter, { fn report<'a, M: Into>>(&self, key: M, report: &mut Report) { match self { Err(_) => { report.insert(key.into().into_owned(), false); } Ok(item) => { item.report(key, report); } } } } impl Reporter for Option where T: Reporter, { fn report<'a, M: Into>>(&self, key: M, report: &mut Report) { if let Some(item) = self { item.report(key, report); } } } impl Reporter for bool { fn report<'a, M: Into>>(&self, key: M, report: &mut Report) { report.insert(key.into().into_owned(), *self); } } impl Reporter for () { fn report<'a, M: Into>>(&self, key: M, report: &mut Report) { report.insert(key.into().into_owned(), true); } }