1use serde::{Deserialize, Serialize};
2use std::fmt;
3
4#[derive(Debug, Copy, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Default)]
5#[serde(rename_all = "lowercase")]
6pub enum Level {
7 None,
8 Low,
9 #[default]
10 Medium,
11 High,
12}
13
14impl fmt::Display for Level {
15 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
16 use Level::*;
17 f.write_str(match self {
18 None => "none",
19 Low => "low",
20 Medium => "medium",
21 High => "high",
22 })
23 }
24}
25
26#[derive(thiserror::Error, Debug)]
27#[error("Can't convert string to Level")]
28pub struct FromStrErr;
29
30impl std::str::FromStr for Level {
31 type Err = FromStrErr;
32
33 fn from_str(s: &str) -> std::result::Result<Level, FromStrErr> {
34 Ok(match s {
35 "none" => Level::None,
36 "low" => Level::Low,
37 "medium" => Level::Medium,
38 "high" => Level::High,
39 _ => return Err(FromStrErr),
40 })
41 }
42}