1 个不稳定版本
0.1.1 | 2022年9月27日 |
---|---|
0.1.0 |
|
#26 in #inter-process
9KB
Gutters
为勇敢的管道工提供的快速而简单的工具
gutters
提供了非常基本的泛型函数,用于构建快速而简单的进程间或网络协议。包含排水管道的隐喻。
Python 绑定可在此处找到。
使用方法
将以下内容添加到您的 Cargo.toml
[dependencies]
gutters = "0.1.0"
使用此库非常简单
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)?;