aboutsummaryrefslogtreecommitdiff
path: root/server/src/message.rs
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/message.rs')
-rw-r--r--server/src/message.rs25
1 files changed, 17 insertions, 8 deletions
diff --git a/server/src/message.rs b/server/src/message.rs
index c248fff8..79c004a2 100644
--- a/server/src/message.rs
+++ b/server/src/message.rs
@@ -46,28 +46,37 @@ macro_rules! trm_param {
};
}
-pub struct TrError {
- pub id: &'static str,
- pub params: Vec<Message>,
+pub enum TrError {
+ Tr {
+ id: &'static str,
+ params: Vec<Message>,
+ },
+ Plain(String),
}
impl From<TrError> for Message {
fn from(value: TrError) -> Self {
- Self::Translation {
- id: value.id.to_owned(),
- params: value.params,
+ match value {
+ TrError::Tr { id, params } => Self::Translation {
+ id: id.to_owned(),
+ params,
+ },
+ TrError::Plain(s) => Self::Text(s),
}
}
}
impl Debug for TrError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- write!(f, "{} {:?}", tr(self.id), self.params)
+ match self {
+ TrError::Tr { id, params } => write!(f, "{} {:?}", tr(id), params),
+ TrError::Plain(s) => write!(f, "{s}"),
+ }
}
}
#[macro_export]
macro_rules! tre {
($id:literal $(, $typ:ident = $param:expr)*) => {
- crate::message::TrError {
+ crate::message::TrError::Tr {
id: $id,
params: vec![$(crate::tre_param!($typ, $param)),*]
}