Turn report to a struct

This commit is contained in:
Roey Darwish Dror
2018-08-24 21:52:17 +03:00
parent eb133bff6b
commit 5fb2686e56
2 changed files with 52 additions and 40 deletions

View File

@@ -1,13 +1,28 @@
use std::borrow::Cow;
type CowString<'a> = Cow<'a, str>;
pub type Report<'a> = Vec<(CowString<'a>, bool)>;
pub struct Report<'a> {
data: Vec<(CowString<'a>, bool)>,
}
pub fn report<'a, M: Into<CowString<'a>>>(report: &mut Report<'a>, result: Option<(M, bool)>) {
if let Some((key, success)) = result {
let key = key.into();
impl<'a> Report<'a> {
pub fn new() -> Self {
Self { data: Vec::new() }
}
debug_assert!(!report.iter().any(|(k, _)| k == &key), "{} already reported", key);
report.push((key, success));
pub fn push_result<M>(&mut self, result: Option<(M, bool)>)
where
M: Into<CowString<'a>>,
{
if let Some((key, success)) = result {
let key = key.into();
debug_assert!(!self.data.iter().any(|(k, _)| k == &key), "{} already reported", key);
self.data.push((key, success));
}
}
pub fn data(&self) -> &Vec<(CowString<'a>, bool)> {
&self.data
}
}