Middleman
aims to make sending structures over a network easy. It is built on top of mio
, and is in the same spirit as the library wire
.
```Rust struct M: Message ↑ ╷ ┆ ┆
Middleman (⌐■_■)
TCP
~~~~~~~~~
▲ ▼
▲ bytes ▼
▲ ▼
~~~~~~~~~
TCP
Middleman (⌐■_■)
┆ ┆
╵ ↓
struct M: Message ```
This library aims to provide a number of structs that implement the Middleman
trait. At present, the only one available is Threadless
, which leans on mio
's non-blocking reads to support blocking and non-blocking sends and receives without requiring additional threads.
Message
for any types T
you want to send or receive. (This involves implementing the serde
library's serialization traits. In most cases the serde_derive
macros are just fine).
```Rust
enum X {
A,
B(u32),
C(Vec
mio::TcpStream
object(s). See the documentation for mio
for more information.MiddleMan
implmentor.
Rust
use middleman::{Middleman, Threadless};
let mut mm = Threadless::new(stream);
That's it. Messages from your peer can be received using recv()
(blocking) or try_recv()
(non-blocking).
```Rust
use middleman::{TryRecvError};
// blocking receive
let x1 = mm.recv::
// non-blocking receive
loop {
dowork();
match mm.tryrecv::
See src/tests.rs
for an example of a typical use case.