Skip to main content

middleware_core/
qos.rs

1use std::collections::HashMap;
2
3#[derive(Clone, Copy, Debug, Eq, PartialEq)]
4pub struct QosProfile {
5    pub reliable: bool,
6    pub depth: usize,
7}
8
9impl Default for QosProfile {
10    fn default() -> Self {
11        Self {
12            reliable: true,
13            depth: 16,
14        }
15    }
16}
17
18#[derive(Default)]
19pub struct QosStore {
20    topics: HashMap<String, QosProfile>,
21}
22
23impl QosStore {
24    pub fn set_topic_qos(&mut self, topic: impl Into<String>, profile: QosProfile) {
25        self.topics.insert(topic.into(), profile);
26    }
27
28    pub fn set_topic_qos_if_absent(&mut self, topic: impl Into<String>, profile: QosProfile) {
29        self.topics.entry(topic.into()).or_insert(profile);
30    }
31
32    pub fn topic_qos(&self, topic: &str) -> Option<QosProfile> {
33        self.topics.get(topic).copied()
34    }
35}