use tokio::sync::mpsc;
use zbus::object_server::SignalEmitter;
use super::Mk;
#[derive(Debug, Clone)]
pub enum Mr {
T(MrT),
F(MrF),
SE(SignalEmitter<'static>),
K(mpsc::Sender<Mk>),
}
const MR_T: &'static str = "t";
const MR_F: &'static str = "f";
impl Mr {
pub fn from(s: String) -> Option<Mr> {
match s.find(' ') {
Some(i) => {
let (n, v) = s.split_at(i);
match n {
MR_T => MrT::from(v).map(|m| Mr::T(m)),
MR_F => MrF::from(v).map(|m| Mr::F(m)),
_ => None,
}
}
None => None,
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct MrT(pub String);
impl MrT {
pub fn from(s: &str) -> Option<Self> {
match serde_json::from_str::<String>(s) {
Ok(t) => Some(Self(t)),
_ => None,
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct MrF(pub i32);
impl MrF {
pub fn from(s: &str) -> Option<Self> {
match serde_json::from_str::<i32>(s) {
Ok(i) => Some(Self(i)),
_ => None,
}
}
}