1use std::{cmp::Ordering, collections::HashMap};
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
5pub enum Msgtype {
6 Immediate,
7 Delayed,
8}
9
10#[derive(Debug, Serialize, Deserialize, Clone)]
11pub struct Message {
12 pub topic: String,
13 pub msgid: String,
14 pub msgtype: Msgtype,
15 pub timestamp: u64,
16 pub data: HashMap<String, String>,
17}
18
19impl PartialEq for Message {
20 fn eq(&self, other: &Self) -> bool {
21 self.timestamp == other.timestamp
22 }
23}
24
25impl Eq for Message {}
26
27impl PartialOrd for Message {
28 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
29 Some(self.cmp(other))
30 }
31}
32
33impl Ord for Message {
34 fn cmp(&self, other: &Self) -> Ordering {
35 other.timestamp.cmp(&self.timestamp)
36 }
37}