1use std::fmt;
2
3#[derive(Debug)]
4pub enum MqError {
5 Publish(String),
6 Subscribe(String),
7 Connection(String),
8 NotSupported(String),
9 Json(String),
10}
11
12impl fmt::Display for MqError {
13 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14 match self {
15 MqError::Publish(msg) => write!(f, "Publish error: {}", msg),
16 MqError::Subscribe(msg) => write!(f, "Subscribe error: {}", msg),
17 MqError::Connection(msg) => write!(f, "Connection error: {}", msg),
18 MqError::NotSupported(msg) => write!(f, "Not supported: {}", msg),
19 MqError::Json(msg) => write!(f, "JSON error: {}", msg),
20 }
21 }
22}
23
24impl std::error::Error for MqError {}
25
26impl From<serde_json::Error> for MqError {
27 fn from(err: serde_json::Error) -> Self {
28 MqError::Json(err.to_string())
29 }
30}