1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
use crate::diagnostic::EnsembleDiagnostic;
pub struct GlobalReportingCtxt {
errors: Vec<EnsembleDiagnostic>,
nonfatals: Vec<EnsembleDiagnostic>,
fatal: Option<EnsembleDiagnostic>,
}
impl Default for GlobalReportingCtxt {
fn default() -> Self {
Self::new()
}
}
impl GlobalReportingCtxt {
#[must_use]
pub fn new() -> Self {
Self {
errors: Vec::new(),
nonfatals: Vec::new(),
fatal: None,
}
}
pub fn clear_syncd(&mut self) {
self.errors.clear();
}
pub fn clear_nonfatals(&mut self) {
self.nonfatals.clear();
}
pub fn clear_fatal(&mut self) {
self.fatal = None;
}
pub fn clear(&mut self) {
self.clear_fatal();
self.clear_nonfatals();
self.clear_syncd();
}
pub fn report_syncd(&mut self, value: EnsembleDiagnostic) {
self.errors.push(value);
}
pub fn report_non_fatal(&mut self, value: EnsembleDiagnostic) {
self.nonfatals.push(value);
}
pub fn report_fatal(&mut self, value: EnsembleDiagnostic) {
if self.fatal.is_none() {
self.fatal = Some(value);
}
}
#[must_use]
pub fn nonfatals(&self) -> &[EnsembleDiagnostic] {
&self.nonfatals
}
#[must_use]
pub fn fatal(&self) -> Option<&EnsembleDiagnostic> {
self.fatal.as_ref()
}
#[must_use]
pub fn errors(&self) -> &[EnsembleDiagnostic] {
&self.errors
}
}