Skip to main content

rsiot/message/
msg_data.rs

1use serde::{Deserialize, Serialize};
2
3use super::{MsgDataBound, MsgKey, system_messages::*};
4
5/// Тип сообщения
6#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
7pub enum MsgData<TCustom> {
8    /// Системные сообщения
9    System(System),
10    /// Пользовательские сообщения
11    Custom(TCustom),
12}
13
14impl<TMsg> MsgData<TMsg>
15where
16    TMsg: MsgDataBound,
17{
18    /// Получить ключ сообщения
19    pub fn key(&self) -> String {
20        match &self {
21            MsgData::System(system) => format!("System-{}", system.key()),
22            MsgData::Custom(custom) => format!("Custom-{}", custom.key()),
23        }
24    }
25}
26
27impl<TCustom> MsgData<TCustom> where TCustom: MsgDataBound {}