Turn report to a struct
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user