Crates.io | simple-message-channels |
lib.rs | simple-message-channels |
version | 0.2.0 |
source | src |
created_at | 2019-11-21 17:45:20.471768 |
updated_at | 2020-02-07 01:21:02.732539 |
description | Simple binary protocol with a channel, type, message scheme |
homepage | |
repository | https://github.com/datrs/simple-message-channels |
max_upload_size | |
id | 183267 |
size | 50,760 |
Simple streamable state machine that implements a useful channel, message-type, message pattern.
A port of the JavaScript module simple-message-channels to Rust. Original module by mafintosh.
See examples/.
The following sends three messages, transforms them, and prints the results:
cargo run --example send | cargo run --example echo_upper | cargo run --example recv
This example would read messages from STDIN and echos them back to STDOUT:
async fn echo() -> Result<(), io::Error> {
let stdin = io::stdin().lock().await;
let stdout = io::stdout().lock().await;
let mut reader = Reader::new(stdin);
let mut writer = Writer::new(stdout);
while let Some(msg) = reader.next().await {
let msg = msg?;
writer.send(msg).await?;
}
Ok(())
}