kodept_macros/error/
report_collector.rs1use crate::error::report::Report;
2
3#[derive(Default, Debug)]
4pub struct ReportCollector {
5 reports: Vec<Report>,
6 has_errors: bool,
7}
8
9impl ReportCollector {
10 #[must_use]
11 pub fn new() -> Self {
12 Self::default()
13 }
14
15 pub fn report(&mut self, report: Report) {
16 self.has_errors |= report.is_error();
17 self.reports.push(report);
18 }
19
20 #[must_use]
21 pub const fn has_errors(&self) -> bool {
22 self.has_errors
23 }
24
25 pub fn has_reports(&self) -> bool {
26 !self.reports.is_empty()
27 }
28
29 #[must_use]
30 pub fn into_collected_reports(self) -> Vec<Report> {
31 self.reports
32 }
33
34 pub fn as_collected_reports(&self) -> &[Report] {
35 self.reports.as_slice()
36 }
37}