rsiot/message/
msg_data.rs1use serde::{Deserialize, Serialize};
2
3use super::{system_messages::*, MsgDataBound, MsgKey, TimeToLiveValue};
4
5#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
7pub enum MsgData<TCustom> {
8    System(System),
10    Custom(TCustom),
12}
13
14impl<TMsg> MsgData<TMsg>
15where
16    TMsg: MsgDataBound,
17{
18    pub fn define_time_to_live(&self) -> TimeToLiveValue {
20        match &self {
21            MsgData::System(_) => TimeToLiveValue::Infinite,
22            MsgData::Custom(data) => data.define_time_to_live(),
23        }
24    }
25
26    pub fn key(&self) -> String {
28        match &self {
29            MsgData::System(system) => format!("System-{}", system.key()),
30            MsgData::Custom(custom) => format!("Custom-{}", custom.key()),
31        }
32    }
33}
34
35impl<TCustom> MsgData<TCustom> where TCustom: MsgDataBound {}