diidi_travel_common_queue/
feature.rs1use std::collections::HashSet;
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
4pub enum QueueFeature {
5 Delay,
6 Headers,
7 Keyed,
8 Partition,
9 BatchPublish,
10 BatchConsume,
11 DeadLetter,
12 Transactions,
13}
14
15impl QueueFeature {
16 pub fn as_str(&self) -> &'static str {
17 match self {
18 QueueFeature::Delay => "delay",
19 QueueFeature::Headers => "headers",
20 QueueFeature::Keyed => "keyed",
21 QueueFeature::Partition => "partition",
22 QueueFeature::BatchPublish => "batch_publish",
23 QueueFeature::BatchConsume => "batch_consume",
24 QueueFeature::DeadLetter => "dead_letter",
25 QueueFeature::Transactions => "transactions",
26 }
27 }
28}
29
30#[derive(Debug, Clone, Default)]
31pub struct QueueFeatures {
32 supported: HashSet<QueueFeature>,
33}
34
35impl QueueFeatures {
36 pub fn new(features: impl IntoIterator<Item = QueueFeature>) -> Self {
37 Self { supported: features.into_iter().collect() }
38 }
39
40 pub fn with(mut self, feature: QueueFeature) -> Self {
41 self.supported.insert(feature);
42 self
43 }
44
45 pub fn supports(&self, feature: QueueFeature) -> bool {
46 self.supported.contains(&feature)
47 }
48
49 pub fn is_empty(&self) -> bool {
50 self.supported.is_empty()
51 }
52}