Files
topgrade/src/report.rs

46 lines
995 B
Rust
Raw Normal View History

2018-06-03 18:04:58 +03:00
use std::borrow::Cow;
pub enum StepResult {
Success,
Failure,
Ignored,
2020-08-21 23:04:36 +03:00
Skipped(String),
}
impl StepResult {
2020-08-21 23:04:36 +03:00
pub fn failed(&self) -> bool {
2021-10-28 22:05:35 +03:00
match self {
StepResult::Success | StepResult::Ignored | StepResult::Skipped(_) => false,
StepResult::Failure => true,
}
}
}
2018-06-27 18:06:24 +03:00
type CowString<'a> = Cow<'a, str>;
type ReportData<'a> = Vec<(CowString<'a>, StepResult)>;
2018-08-24 21:52:17 +03:00
pub struct Report<'a> {
data: ReportData<'a>,
2018-08-24 21:52:17 +03:00
}
impl<'a> Report<'a> {
pub fn new() -> Self {
Self { data: Vec::new() }
}
2018-06-03 18:04:58 +03:00
pub fn push_result<M>(&mut self, result: Option<(M, StepResult)>)
2018-08-24 21:52:17 +03:00
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));
}
}
2018-06-06 15:32:38 +03:00
pub fn data(&self) -> &ReportData<'a> {
2018-08-24 21:52:17 +03:00
&self.data
2018-06-06 15:32:38 +03:00
}
}