vrl/diagnostic/
severity.rs

1use codespan_reporting::diagnostic;
2
3#[derive(Debug, PartialEq, Eq, Clone, Copy)]
4pub enum Severity {
5    Bug,
6    Error,
7    Warning,
8    Note,
9}
10
11impl Severity {
12    /// Returns `true` if the severity is a [bug](Severity::Bug).
13    #[inline]
14    #[must_use]
15    pub fn is_bug(self) -> bool {
16        matches!(self, Severity::Bug)
17    }
18
19    /// Returns `true` if the severity is an [error](Severity::Error).
20    #[inline]
21    #[must_use]
22    pub fn is_error(self) -> bool {
23        matches!(self, Severity::Error)
24    }
25
26    /// Returns `true` if the severity is a [warning](Severity::Warning).
27    #[inline]
28    #[must_use]
29    pub fn is_warning(self) -> bool {
30        matches!(self, Severity::Warning)
31    }
32
33    /// Returns `true` if the severity is a [note](Severity::Note).
34    #[inline]
35    #[must_use]
36    pub fn is_note(self) -> bool {
37        matches!(self, Severity::Note)
38    }
39}
40
41impl From<Severity> for diagnostic::Severity {
42    fn from(severity: Severity) -> Self {
43        use Severity::{Bug, Error, Note, Warning};
44
45        match severity {
46            Bug => diagnostic::Severity::Bug,
47            Error => diagnostic::Severity::Error,
48            Warning => diagnostic::Severity::Warning,
49            Note => diagnostic::Severity::Note,
50        }
51    }
52}