use serde::{Deserialize, Serialize};
use std::str::FromStr;
use strum::Display;
#[derive(
Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, Display,
)]
#[serde(rename_all = "lowercase")]
#[strum(serialize_all = "lowercase")]
pub enum Severity {
Debug,
Info,
Notice,
Warning,
Error,
Critical,
}
impl Severity {
#[inline]
pub fn as_str(&self) -> &'static str {
match self {
Self::Debug => "debug",
Self::Info => "info",
Self::Notice => "notice",
Self::Warning => "warning",
Self::Error => "error",
Self::Critical => "critical",
}
}
pub const fn all() -> [Self; 6] {
[
Self::Debug,
Self::Info,
Self::Notice,
Self::Warning,
Self::Error,
Self::Critical,
]
}
}
impl FromStr for Severity {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"debug" => Ok(Self::Debug),
"info" => Ok(Self::Info),
"notice" => Ok(Self::Notice),
"warning" => Ok(Self::Warning),
"error" => Ok(Self::Error),
"critical" => Ok(Self::Critical),
_ => Err(format!("Invalid severity level: '{}'", s)),
}
}
}