Files
tuliprox/shared/src/model/messaging.rs
T
euzuandGitHub 38813bb672 Feature/makefile ci and log with local time (#582)
- Add Makefile to simplify installing required tools
- Add CONTRIBUTING.md welcome new contributors
- Add fmt, lint, test tasks to makefile and update CONTRIBUTING.md
- Add CI workflow
-  Log with local date
2026-02-14 12:12:59 +01:00

50 lines
1.3 KiB
Rust

use crate::{concat_string, error::TuliproxError, info_err_res};
use std::{fmt, str::FromStr};
#[derive(Debug, Copy, Clone, serde::Serialize, serde::Deserialize, PartialEq, Eq, Hash)]
pub enum MsgKind {
#[serde(rename = "info")]
Info,
#[serde(rename = "stats")]
Stats,
#[serde(rename = "error")]
Error,
#[serde(rename = "watch")]
Watch,
}
impl MsgKind {
pub fn template_filename(&self, prefix: &str) -> String {
concat_string!(prefix, "_", &self.to_string().to_lowercase(), ".templ")
}
}
impl fmt::Display for MsgKind {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let s = match self {
MsgKind::Info => "Info",
MsgKind::Stats => "Stats",
MsgKind::Error => "Error",
MsgKind::Watch => "Watch",
};
write!(f, "{s}")
}
}
impl FromStr for MsgKind {
type Err = TuliproxError;
fn from_str(s: &str) -> Result<Self, TuliproxError> {
if s.eq_ignore_ascii_case("info") {
Ok(Self::Info)
} else if s.eq_ignore_ascii_case("stats") {
Ok(Self::Stats)
} else if s.eq_ignore_ascii_case("error") {
Ok(Self::Error)
} else if s.eq_ignore_ascii_case("watch") {
Ok(Self::Watch)
} else {
info_err_res!("Unknown MsgKind: {}", s)
}
}
}