Crate suplex

Crate suplex 

Source
Expand description

Request-Response wrapper over MPMC Crossbeam channels

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.

§The Left-Right Concept

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).

§Example Use Case

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.

§Too Complicated?

If the Left and Right concept is confusing, you don’t have to use the Bridge at all and can create queue pairs with the following functions:

This allows you to have full control of the channels and you can implement your logic as you please.

Structs§

Bridge
The Bridge containing the Left and Right channels.
Iter
A blocking iterator over messages in a channel.
Receiver
The receiving side of a channel.
RecvError
An error returned from the recv method.
SendError
An error returned from the send method.
Sender
The sending side of a channel.
TryIter
A non-blocking iterator over messages in a channel.

Enums§

RecvTimeoutError
An error returned from the recv_timeout method.
SendTimeoutError
An error returned from the send_timeout method.
TryRecvError
An error returned from the try_recv method.
TrySendError
An error returned from the try_send method.

Functions§

bounded_bridge
Creates two pairs of bounded channels for the Left and Right types
left_bounded_bridge
Creates two pairs of channels for the Left and Right types with the Left side bounded.
right_bounded_bridge
Creates two pairs of channels for the Left and Right types with the Right side bounded.
unbounded_bridge
Creates two pairs of unbounded channels for the Left and Right types

Type Aliases§

LeftChannelSplit
Channel split containing the Left channels (Sender<L> & Receiver<R>)
RightChannelSplit
Channel split containing the Right channels (Sender<R> & Receiver<L>)