orrery_parser/error/severity.rs
1//! Severity levels for diagnostics.
2//!
3//! This module defines the severity of diagnostic messages,
4//! distinguishing between fatal errors and advisory warnings.
5
6use std::fmt;
7
8/// The severity level of a diagnostic.
9///
10/// Severity determines how the diagnostic should be handled:
11/// - [`Severity::Error`] indicates a fatal issue that must be fixed
12/// - [`Severity::Warning`] indicates an advisory issue that should be addressed
13#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
14pub enum Severity {
15 /// A fatal error that prevents successful compilation.
16 ///
17 /// Errors must be fixed before the diagram can be processed.
18 Error,
19
20 /// A non-fatal warning about potential issues.
21 ///
22 /// Warnings indicate code that may be problematic but doesn't
23 /// prevent compilation from succeeding.
24 Warning,
25}
26
27impl Severity {
28 /// Returns `true` if this is an error severity.
29 pub fn is_error(&self) -> bool {
30 matches!(self, Severity::Error)
31 }
32
33 /// Returns `true` if this is a warning severity.
34 pub fn is_warning(&self) -> bool {
35 matches!(self, Severity::Warning)
36 }
37}
38
39impl fmt::Display for Severity {
40 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
41 match self {
42 Severity::Error => write!(f, "error"),
43 Severity::Warning => write!(f, "warning"),
44 }
45 }
46}