use core::fmt;
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum Severity {
Error,
Warning,
Note,
Help,
}
impl Severity {
#[inline]
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::Error => "error",
Self::Warning => "warning",
Self::Note => "note",
Self::Help => "help",
}
}
}
impl fmt::Display for Severity {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}
#[cfg(test)]
mod tests {
extern crate alloc;
use alloc::string::ToString;
use super::*;
#[test]
fn test_as_str_matches_each_level() {
assert_eq!(Severity::Error.as_str(), "error");
assert_eq!(Severity::Warning.as_str(), "warning");
assert_eq!(Severity::Note.as_str(), "note");
assert_eq!(Severity::Help.as_str(), "help");
}
#[test]
fn test_display_equals_as_str() {
assert_eq!(Severity::Error.to_string(), "error");
assert_eq!(Severity::Note.to_string(), "note");
}
#[test]
fn test_order_runs_most_to_least_serious() {
assert!(Severity::Error < Severity::Warning);
assert!(Severity::Warning < Severity::Note);
assert!(Severity::Note < Severity::Help);
}
}