Skip to main content

#
typed_derive/
foreign_crate.rs

    1#[derive(Copy, Clone, PartialEq, Eq, Debug)]
    2pub(crate) enum LogLevel {
    3    Trace,
    4    Debug,
    5    Info,
    6    Warn,
    7    Error,
    8}
    9
    10impl std::fmt::Display for LogLevel {
    11    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
    12        let s = match self {
    13            Self::Trace => "trace",
    14            Self::Debug => "debug",
    15            Self::Info => "info",
    16            Self::Warn => "warn",
    17            Self::Error => "error",
    18        };
    19        s.fmt(f)
    20    }
    21}
    22impl std::str::FromStr for LogLevel {
    23    type Err = String;
    24
    25    fn from_str(s: &str) -> Result<Self, Self::Err> {
    26        match s {
    27            "trace" => Ok(Self::Trace),
    28            "debug" => Ok(Self::Debug),
    29            "info" => Ok(Self::Info),
    30            "warn" => Ok(Self::Warn),
    31            "error" => Ok(Self::Error),
    32            _ => Err(format!("Unknown log level: {s}")),
    33        }
    34    }
    35}