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
use crate::Result; use std::fmt; #[derive(Debug, Copy, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)] #[serde(rename_all = "lowercase")] pub enum Level { None, Low, Medium, High, } impl Default for Level { fn default() -> Self { Level::Medium } } impl fmt::Display for Level { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { use self::Level::*; f.write_str(match self { None => "none", Low => "low", Medium => "medium", High => "high", }) } } impl Level { #[allow(unused)] fn from_str(s: &str) -> Result<Level> { Ok(match s { "none" => Level::None, "low" => Level::Low, "medium" => Level::Medium, "high" => Level::High, _ => bail!("Unknown level: {}", s), }) } }