use std::fmt::{
Display,
Formatter,
};
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum Topic {
TMs,
ThreadTyping,
OrcaPresence,
LsReq,
LsResp,
LsForegroundState,
LsAppSettings,
NotifyDisconnect,
Unknown(String),
}
impl Topic {
pub fn parse(value: &str) -> Self {
match value {
"/t_ms" => Self::TMs,
"/thread_typing" => Self::ThreadTyping,
"/orca_presence" => Self::OrcaPresence,
"/ls_req" => Self::LsReq,
"/ls_resp" => Self::LsResp,
"/ls_foreground_state" => Self::LsForegroundState,
"/ls_app_settings" => Self::LsAppSettings,
"/notify_disconnect" => Self::NotifyDisconnect,
unknown => Self::Unknown(unknown.to_string()),
}
}
pub fn as_str(&self) -> &str {
match self {
Self::TMs => "/t_ms",
Self::ThreadTyping => "/thread_typing",
Self::OrcaPresence => "/orca_presence",
Self::LsReq => "/ls_req",
Self::LsResp => "/ls_resp",
Self::LsForegroundState => "/ls_foreground_state",
Self::LsAppSettings => "/ls_app_settings",
Self::NotifyDisconnect => "/notify_disconnect",
Self::Unknown(value) => value,
}
}
pub fn name(&self) -> &'static str {
match self {
Self::TMs => "t_ms",
Self::ThreadTyping => "thread_typing",
Self::OrcaPresence => "orca_presence",
Self::LsReq => "lightspeed_request",
Self::LsResp => "lightspeed_response",
Self::LsForegroundState => "lightspeed_foreground_state",
Self::LsAppSettings => "lightspeed_app_settings",
Self::NotifyDisconnect => "notify_disconnect",
Self::Unknown(_) => "unknown",
}
}
}
impl Display for Topic {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.write_str(self.as_str())
}
}