40 lines
909 B
Rust
40 lines
909 B
Rust
use serde::Deserialize;
|
|
pub use std::convert::TryFrom;
|
|
|
|
// pub type Level = u8;
|
|
|
|
#[derive(Debug, Clone, Eq, PartialEq, PartialOrd, Hash, Deserialize)]
|
|
pub enum Level {
|
|
Debug = 0,
|
|
Notice = 1,
|
|
Anomaly = 2,
|
|
Issue = 3,
|
|
Critical = 4,
|
|
}
|
|
|
|
impl TryFrom<&str> for Level {
|
|
type Error = ();
|
|
fn try_from(level: &str) -> Result<Self, ()> {
|
|
match serde_yaml::from_str(level) {
|
|
Ok(v) => v,
|
|
_ => Err(()),
|
|
}
|
|
// match level {
|
|
// "Debug" => Ok(Level::Debug),
|
|
// "Notice" => Ok(Level::Notice),
|
|
// "Anomaly" => Ok(Level::Anomaly),
|
|
// "Issue" => Ok(Level::Issue),
|
|
// "Critical" => Ok(Level::Critical),
|
|
// _ => Err(()),
|
|
// }
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct Message {
|
|
pub emitter: String,
|
|
pub level: Level,
|
|
pub msg_type: String,
|
|
pub text: String,
|
|
}
|