graphql_composition/
diagnostics.rs1#[derive(Default, Debug)]
3pub struct Diagnostics(Vec<Diagnostic>);
4
5impl Diagnostics {
6 pub fn any_fatal(&self) -> bool {
8 self.0.iter().any(|diagnostic| diagnostic.is_fatal)
9 }
10
11 pub fn iter_warnings(&self) -> impl Iterator<Item = &str> {
13 self.0
14 .iter()
15 .filter(|diagnostic| !diagnostic.is_fatal)
16 .map(|diagnostic| diagnostic.message.as_str())
17 }
18
19 pub fn iter_errors(&self) -> impl Iterator<Item = &str> {
21 self.0
22 .iter()
23 .filter(|diagnostic| diagnostic.is_fatal)
24 .map(|diagnostic| diagnostic.message.as_str())
25 }
26
27 pub(crate) fn clone_all_from(&mut self, other: &Diagnostics) {
28 self.0.extend(other.0.iter().cloned())
29 }
30
31 pub fn iter_messages(&self) -> impl Iterator<Item = &str> {
33 self.0.iter().map(|diagnostic| diagnostic.message.as_str())
34 }
35
36 pub(crate) fn push_fatal(&mut self, message: String) {
37 self.0.push(Diagnostic {
38 message,
39 is_fatal: true,
40 });
41 }
42
43 pub(crate) fn push_warning(&mut self, message: String) {
44 self.0.push(Diagnostic {
45 message,
46 is_fatal: false,
47 });
48 }
49}
50
51#[derive(Debug, Clone)]
53pub(crate) struct Diagnostic {
54 message: String,
55 is_fatal: bool,
57}