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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
#[derive(Clone)] pub enum Severity { Debug, Info, Warn, Error, } impl Severity { pub fn from_str(string: impl AsRef<str>) -> Option<Severity> { match string.as_ref() { "debug" => Some(Severity::Debug), "info" => Some(Severity::Info), "warn" => Some(Severity::Warn), "error" => Some(Severity::Error), _ => None, } } pub fn to_level(&self) -> i32 { match self { Severity::Debug => -1, Severity::Info => 0, Severity::Warn => 1, Severity::Error => 2, } } pub fn to_str(&self) -> &'static str { match self { Severity::Debug => "debug", Severity::Info => "info", Severity::Warn => "warn", Severity::Error => "error", } } pub fn to_aligned_str(&self) -> &'static str { match self { Severity::Debug => "DEBG", Severity::Info => "INFO", Severity::Warn => "WARN", Severity::Error => "ERRO", } } pub fn to_icon(&self) -> &'static str { match self { Severity::Debug => "", Severity::Info => "", Severity::Warn => "", Severity::Error => "", } } } impl Default for Severity { fn default() -> Severity { Severity::Info } }