Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]

members = [
"taurus_poc"
"taurus_poc", "taurus_queue",
]
6 changes: 6 additions & 0 deletions taurus_queue/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "taurus_queue"
version = "0.1.0"
edition = "2021"

[dependencies]
61 changes: 61 additions & 0 deletions taurus_queue/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
pub mod queue {

use std::ops::Add;

/// # Queue Prefix
/// - Every incoming message will have the `Send` prefix
/// - Every processed message (answer) from taurus will have the `Receive` prefix
pub enum QueuePrefix {
Send,
Receive,
}

/// Supported Protocols
pub enum QueueProtocol {
Rest,
WebSocket,
}

/// Implementation to turn a protocol into a str
impl QueueProtocol {

/// Function to turn a protocol into a str
///
/// # Example:
/// ```
/// use taurus_queue::queue::QueueProtocol;
/// let proto_str = QueueProtocol::Rest.as_str().to_string();
/// let result = "REST".to_string();
///
/// assert_eq!(result, proto_str);
/// ```
pub fn as_str(&self) -> &'static str {
match self {
QueueProtocol::Rest => "REST",
QueueProtocol::WebSocket => "WS",
}
}
}

/// Implementation to add a prefix and a protocol to a queue name
impl Add<QueueProtocol> for QueuePrefix {
type Output = String;

/// Function to add a prefix and a protocol to a queue name
///
/// # Example:
/// ```
/// use taurus_queue::queue::{QueuePrefix, QueueProtocol};
/// let send_rest_queue_name = QueuePrefix::Send + QueueProtocol::Rest;
/// let result = "S_REST".to_string();
///
/// assert_eq!(result, send_rest_queue_name);
/// ```
fn add(self, rhs: QueueProtocol) -> Self::Output {
match self {
QueuePrefix::Send => "S_".to_string() + rhs.as_str(),
QueuePrefix::Receive => "R_".to_string() + rhs.as_str(),
}
}
}
}