Skip to main content

Crate gutters

Crate gutters 

Source
Expand description

This library provides very very basic generic functions for building quick and dirty interprocess or network protocols. Sewer metaphors included.

§Usage

use gutters::{pick_up, throw, hail, wait, throw_and_wait, pick_up_and_hail};

// Here we use a TcpStream as a "gutter", but anything implementing
// Read and Write will do.
use std::net::TcpStream;
let mut stream = TcpStream::connect("127.0.0.1:34254");
// Of course, here you need a server on the other side.

// You can "throw" data down the "gutter" with the corresponding
// function. The other side will have to "pick-up" the corresponding
// message (or "log", if you want to pursue the metaphor).
let log = 123.4f64
throw(&mut stream, &log)?;

// You can "throw" as many "logs" as you want, while the other end
// "picks them up".
let log = 567.8f64
throw(&mut stream, &log)?;
throw(&mut stream, &log)?;

// You can also "pick-up logs".
let mut log = 0.0f64;
pick_up(&mut stream, &mut log)?;
println!("{}", log)?;
pick_up(&mut stream, &mut log)?;
println!("{}", log)?;

// If you need to synchronize with the other end, you can "hail" to
// them. They will have to "wait" for you.
hail(&mut stream)?;

// You can also "wait" for the other end to "hail" you.
wait(&mut stream)?;

// If you want to be synchronized with the other end at all time,
// you may use the `pick_up_and_hail` and `throw_and_wait` variants.
let log = 567.8f64
throw_and_wait(&mut stream, &log)?;

let mut log = 0.0f64;
pick_up_and_hail(&mut stream, &mut log)?;
println!("{}", log)?;

Functions§

hail
Send an acknowledgment to the gutter.
pick_up
Read a message of type T from the gutter.
pick_up_and_hail
Read a message of type T from the gutter, and send an acknowledgement.
throw
Send a message of type T to the gutter.
throw_and_wait
Send a message of type T to the gutter, and wait for an acknowledgement.
wait
Wait for an acknowledgment from the gutter.