ruststream_lapin/
exchange.rs1use lapin::ExchangeKind;
4
5#[derive(Debug, Clone, PartialEq, Eq)]
20pub struct RabbitExchange {
21 name: String,
22 kind: ExchangeKind,
23 durable: bool,
24 auto_delete: bool,
25}
26
27impl RabbitExchange {
28 fn new(name: impl Into<String>, kind: ExchangeKind) -> Self {
29 Self {
30 name: name.into(),
31 kind,
32 durable: true,
33 auto_delete: false,
34 }
35 }
36
37 #[must_use]
39 pub fn direct(name: impl Into<String>) -> Self {
40 Self::new(name, ExchangeKind::Direct)
41 }
42
43 #[must_use]
45 pub fn topic(name: impl Into<String>) -> Self {
46 Self::new(name, ExchangeKind::Topic)
47 }
48
49 #[must_use]
51 pub fn fanout(name: impl Into<String>) -> Self {
52 Self::new(name, ExchangeKind::Fanout)
53 }
54
55 #[must_use]
57 pub fn headers(name: impl Into<String>) -> Self {
58 Self::new(name, ExchangeKind::Headers)
59 }
60
61 #[must_use]
63 pub fn custom(name: impl Into<String>, kind: impl Into<String>) -> Self {
64 Self::new(name, ExchangeKind::Custom(kind.into()))
65 }
66
67 #[must_use]
69 pub fn durable(mut self, durable: bool) -> Self {
70 self.durable = durable;
71 self
72 }
73
74 #[must_use]
76 pub fn auto_delete(mut self, auto_delete: bool) -> Self {
77 self.auto_delete = auto_delete;
78 self
79 }
80
81 #[must_use]
83 pub fn name(&self) -> &str {
84 &self.name
85 }
86
87 pub(crate) fn kind(&self) -> &ExchangeKind {
88 &self.kind
89 }
90
91 pub(crate) fn is_durable(&self) -> bool {
92 self.durable
93 }
94
95 pub(crate) fn is_auto_delete(&self) -> bool {
96 self.auto_delete
97 }
98}