|
| 1 | +pub mod queue { |
| 2 | + |
| 3 | + use std::ops::Add; |
| 4 | + |
| 5 | + /// # Queue Prefix |
| 6 | + /// - Every incoming message will have the `Send` prefix |
| 7 | + /// - Every processed message (answer) from taurus will have the `Receive` prefix |
| 8 | + pub enum QueuePrefix { |
| 9 | + Send, |
| 10 | + Receive, |
| 11 | + } |
| 12 | + |
| 13 | + /// Supported Protocols |
| 14 | + pub enum QueueProtocol { |
| 15 | + Rest, |
| 16 | + WebSocket, |
| 17 | + } |
| 18 | + |
| 19 | + /// Implementation to turn a protocol into a str |
| 20 | + impl QueueProtocol { |
| 21 | + |
| 22 | + /// Function to turn a protocol into a str |
| 23 | + /// |
| 24 | + /// # Example: |
| 25 | + /// ``` |
| 26 | + /// use taurus_queue::queue::QueueProtocol; |
| 27 | + /// let proto_str = QueueProtocol::Rest.as_str().to_string(); |
| 28 | + /// let result = "REST".to_string(); |
| 29 | + /// |
| 30 | + /// assert_eq!(result, proto_str); |
| 31 | + /// ``` |
| 32 | + pub fn as_str(&self) -> &'static str { |
| 33 | + match self { |
| 34 | + QueueProtocol::Rest => "REST", |
| 35 | + QueueProtocol::WebSocket => "WS", |
| 36 | + } |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + /// Implementation to add a prefix and a protocol to a queue name |
| 41 | + impl Add<QueueProtocol> for QueuePrefix { |
| 42 | + type Output = String; |
| 43 | + |
| 44 | + /// Function to add a prefix and a protocol to a queue name |
| 45 | + /// |
| 46 | + /// # Example: |
| 47 | + /// ``` |
| 48 | + /// use taurus_queue::queue::{QueuePrefix, QueueProtocol}; |
| 49 | + /// let send_rest_queue_name = QueuePrefix::Send + QueueProtocol::Rest; |
| 50 | + /// let result = "S_REST".to_string(); |
| 51 | + /// |
| 52 | + /// assert_eq!(result, send_rest_queue_name); |
| 53 | + /// ``` |
| 54 | + fn add(self, rhs: QueueProtocol) -> Self::Output { |
| 55 | + match self { |
| 56 | + QueuePrefix::Send => "S_".to_string() + rhs.as_str(), |
| 57 | + QueuePrefix::Receive => "R_".to_string() + rhs.as_str(), |
| 58 | + } |
| 59 | + } |
| 60 | + } |
| 61 | +} |
0 commit comments