Skip to content

Commit ba439b8

Browse files
Merge pull request #8 from code0-tech/2-add-flow-queue
2 add flow queue
2 parents 7f12fa7 + 1e79a18 commit ba439b8

4 files changed

Lines changed: 72 additions & 1 deletion

File tree

Cargo.lock

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[workspace]
22

33
members = [
4-
"taurus_poc"
4+
"taurus_poc", "taurus_queue",
55
]

taurus_queue/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[package]
2+
name = "taurus_queue"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]

taurus_queue/src/lib.rs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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

Comments
 (0)