rsiot/message/
msg_data.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use serde::{Deserialize, Serialize};

use super::{system_messages::*, MsgDataBound, TimeToLiveValue};

/// Тип сообщения
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub enum MsgData<TCustom> {
    /// Системные сообщения
    System(System),
    /// Пользовательские сообщения
    Custom(TCustom),
}

impl<TMsg> MsgData<TMsg>
where
    TMsg: MsgDataBound,
{
    /// Задать ограничение времени жизни сообщения
    pub fn define_time_to_live(&self) -> TimeToLiveValue {
        match &self {
            MsgData::System(_) => TimeToLiveValue::Infinite,
            MsgData::Custom(data) => data.define_time_to_live(),
        }
    }
}

impl<TCustom> MsgData<TCustom> where TCustom: MsgDataBound {}