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
use codespan_reporting::diagnostic::{Diagnostic, Severity};
type FileId = ();
#[derive(Debug, Clone, Default, PartialEq)]
pub struct Diagnostics(Vec<Diagnostic<FileId>>);
impl Diagnostics {
pub fn new() -> Self { Diagnostics(Vec::new()) }
pub fn iter(&self) -> impl Iterator<Item = &'_ Diagnostic<FileId>> + '_ {
self.0.iter()
}
pub fn iter_severity(
&self,
severity: Severity,
) -> impl Iterator<Item = &'_ Diagnostic<FileId>> + '_ {
self.iter().filter(move |diag| diag.severity >= severity)
}
pub fn has_severity(&self, severity: Severity) -> bool {
self.iter_severity(severity).next().is_some()
}
pub fn has_errors(&self) -> bool { self.has_severity(Severity::Error) }
pub fn has_warnings(&self) -> bool { self.has_severity(Severity::Warning) }
pub fn push(&mut self, diag: Diagnostic<FileId>) { self.0.push(diag); }
pub fn is_empty(&self) -> bool { self.0.is_empty() }
pub fn len(&self) -> usize { self.0.len() }
pub fn drain(&mut self) -> impl Iterator<Item = Diagnostic<()>> + '_ {
self.0.drain(..)
}
}
impl<'a> IntoIterator for &'a Diagnostics {
type IntoIter = <&'a Vec<Diagnostic<FileId>> as IntoIterator>::IntoIter;
type Item = &'a Diagnostic<FileId>;
fn into_iter(self) -> Self::IntoIter { self.0.iter() }
}
impl IntoIterator for Diagnostics {
type IntoIter = <Vec<Diagnostic<FileId>> as IntoIterator>::IntoIter;
type Item = Diagnostic<FileId>;
fn into_iter(self) -> Self::IntoIter { self.0.into_iter() }
}
impl Extend<Diagnostic<FileId>> for Diagnostics {
fn extend<T: IntoIterator<Item = Diagnostic<FileId>>>(&mut self, iter: T) {
self.0.extend(iter);
}
}