| Crates.io | suplex |
| lib.rs | suplex |
| version | 0.1.2 |
| created_at | 2025-09-27 17:18:02.408756+00 |
| updated_at | 2025-09-27 21:23:59.389285+00 |
| description | Request-Response wrapper over Crossbeam channels |
| homepage | https://github.com/Tyrannican/suplex-rs |
| repository | https://github.com/Tyrannican/suplex-rs |
| max_upload_size | |
| id | 1857488 |
| size | 65,865 |
Request/Response MPMC channels powered by Crossbeam!
This crate is designed for situations where you want to have request-response channels shared between two or more processes using the crossbeam_channel crate.
To add it to your project:
cargo add suplex
use suplex::Bridge;
use std::thread;
fn main() {
let bridge: Bridge<usize, usize> = Bridge::unbounded();
let bridge_clone = bridge.clone();
thread::spawn(move || {
while let Ok(value) = bridge_clone.recv_from_left() {
/* do some processing */
let response = 4;
bridge_clone.send_to_left(4).unwrap();
}
});
loop {
/* Some work */
bridge.send_to_right(0).unwrap();
match bridge.recv_from_right() {
Ok(response) => { /* do stuff */ },
Err(e) => panic!("error occurred!"),
}
}
}
This crate revolves around the concept of a Left channel pair and a Right channel pair.
You select one process to be the Left and another process to be the Right.
The Left Process holds a Sender<L> type and a Receiver<R> type that sends messages of
type L (the Left process message type) and receives messages of type R (the Right
process message type).
The Right Process is the inverse which holds a Sender<R> type and a Receiver<L> type
that sends messages of type R (the Right process message type) and receives messages of
type L (the Left process message type).
You have a process in a thread that listens for connections and receives messages. Another process in another thread consumes these messages and returns a response back to the connection process which will send it back to the connected client. Here, you could have a channel to send the incoming messages to the Message consumer process and another channel to return the response.
This crate allows for you to create these channel pairs so that you can share them between processes easily.
Credit to the crossbeam_channel crate for their MPMC implementation