dtcs/diagnostics/
report.rs1use super::{Diagnostic, Severity};
4
5#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
7pub struct DiagnosticReport {
8 pub diagnostics: Vec<Diagnostic>,
10}
11
12pub type ValidationReport = DiagnosticReport;
14
15impl DiagnosticReport {
16 #[must_use]
18 pub fn new() -> Self {
19 Self::default()
20 }
21
22 pub fn push(&mut self, diagnostic: Diagnostic) {
24 self.diagnostics.push(diagnostic);
25 }
26
27 pub fn merge(&mut self, other: DiagnosticReport) {
29 self.diagnostics.extend(other.diagnostics);
30 }
31
32 #[must_use]
34 pub fn is_valid(&self) -> bool {
35 !self.diagnostics.iter().any(|d| d.severity.is_error())
36 }
37
38 #[must_use]
40 pub fn with_min_severity(&self, min: Severity) -> Vec<&Diagnostic> {
41 self.diagnostics
42 .iter()
43 .filter(|d| d.severity >= min)
44 .collect()
45 }
46
47 #[must_use]
49 pub fn errors(&self) -> Vec<&Diagnostic> {
50 self.with_min_severity(Severity::Error)
51 }
52}