Skip to main content

convergio_types/
message_error.rs

1//! Lightweight error wrapper for user-facing messages.
2
3#[derive(Debug, Clone, thiserror::Error)]
4#[error("{0}")]
5pub struct MessageError(pub String);
6
7pub type MessageResult<T> = Result<T, MessageError>;
8
9impl From<String> for MessageError {
10    fn from(value: String) -> Self {
11        Self(value)
12    }
13}
14
15impl From<&str> for MessageError {
16    fn from(value: &str) -> Self {
17        Self(value.to_string())
18    }
19}
20
21macro_rules! impl_message_error_from {
22    ($($ty:ty),* $(,)?) => {
23        $(
24            impl From<$ty> for MessageError {
25                fn from(value: $ty) -> Self {
26                    Self(value.to_string())
27                }
28            }
29        )*
30    };
31}
32
33impl_message_error_from!(std::io::Error, std::net::AddrParseError, serde_json::Error,);