rnetmon/src/message.rs

40 lines
909 B
Rust
Raw Normal View History

2019-02-14 07:21:22 +00:00
use serde::Deserialize;
pub use std::convert::TryFrom;
// pub type Level = u8;
#[derive(Debug, Clone, Eq, PartialEq, PartialOrd, Hash, Deserialize)]
2019-02-05 07:10:55 +00:00
pub enum Level {
2019-02-06 16:42:32 +00:00
Debug = 0,
2019-02-14 07:21:22 +00:00
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(()),
// }
}
2019-02-05 07:10:55 +00:00
}
2019-01-31 10:01:47 +00:00
#[derive(Debug, Clone)]
2019-01-30 15:26:05 +00:00
pub struct Message {
2019-01-31 10:01:47 +00:00
pub emitter: String,
2019-02-05 07:10:55 +00:00
pub level: Level,
2019-01-31 10:01:47 +00:00
pub msg_type: String,
pub text: String,
2019-01-30 22:11:51 +00:00
}