From a702fa55eda5fbb48fd2ea5ecea89d030ea2305a Mon Sep 17 00:00:00 2001 From: metamuffin Date: Wed, 2 Oct 2024 14:47:41 +0200 Subject: translate command errors --- server/src/message.rs | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'server/src/message.rs') 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, +pub enum TrError { + Tr { + id: &'static str, + params: Vec, + }, + Plain(String), } impl From 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)),*] } -- cgit v1.2.3-70-g09d2