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
/// Warnings and errors produced by composition.
#[derive(Default)]
pub struct Diagnostics(Vec<Diagnostic>);

impl Diagnostics {
    pub(crate) fn any_fatal(&self) -> bool {
        self.0.iter().any(|diagnostic| diagnostic.is_fatal)
    }

    /// Iterate over all diagnostic messages.
    pub fn iter_messages(&self) -> impl Iterator<Item = &str> {
        self.0.iter().map(|diagnostic| diagnostic.message.as_str())
    }

    pub(crate) fn push_fatal(&mut self, message: String) {
        self.0.push(Diagnostic {
            message,
            is_fatal: true,
        });
    }
}

/// A composition diagnostic.
pub(crate) struct Diagnostic {
    message: String,
    /// Should this diagnostic be interpreted as a composition failure?
    is_fatal: bool,
}