openvpn_mgmt_codec/
log_level.rs1use std::str::FromStr;
2
3#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
5#[error("unrecognized log level: {0:?}")]
6pub struct ParseLogLevelError(pub String);
7
8#[derive(Debug, Clone, PartialEq, Eq, strum::Display)]
10pub enum LogLevel {
11 #[strum(to_string = "I")]
13 Info,
14
15 #[strum(to_string = "D")]
17 Debug,
18
19 #[strum(to_string = "W")]
21 Warning,
22
23 #[strum(to_string = "N")]
25 NonFatal,
26
27 #[strum(to_string = "F")]
29 Fatal,
30
31 #[strum(default)]
33 Unknown(String),
34}
35
36impl FromStr for LogLevel {
37 type Err = ParseLogLevelError;
38
39 fn from_str(s: &str) -> Result<Self, Self::Err> {
41 match s {
42 "I" => Ok(Self::Info),
43 "D" => Ok(Self::Debug),
44 "W" => Ok(Self::Warning),
45 "N" => Ok(Self::NonFatal),
46 "F" => Ok(Self::Fatal),
47 other => Err(ParseLogLevelError(other.to_string())),
48 }
49 }
50}