qcomms

Crates.ioqcomms
lib.rsqcomms
version1.0.1
sourcesrc
created_at2021-04-19 01:47:25.94425
updated_at2021-07-31 03:17:17.878233
descriptionqcomms is a small library that offers a simple, zero-cost message passing trait. no async-trait.
homepage
repositoryhttps://github.com/znx3p0/qcomms
max_upload_size
id386430
size13,327
(znx3p0)

documentation

https://docs.rs/qcomms/

README

QCOMMS

qcomms is a small library that offers a simple message passing trait. it also offers keepalive and other stream helpers.

use qcomms::ObjComms;
use serde::{Serialize, Deserialize};
use async_std::task;
use async_std::task::sleep;
use async_std::net::{TcpListener, TcpStream};

#[derive(Serialize, Deserialize, Debug)]
pub struct Message {
    hello: String,
    val: u32,
}

#[async_std::main]
async fn main() {
    task::spawn(async move {
        let listener = TcpListener::bind("127.0.0.1:3022").await.unwrap();
        let (mut stream, _) = listener.accept().unwrap();
        let message: Message = stream.rx().await.unwrap();
        println!("{:?}", message);
    });

    let m = Message {
        hello: "hello".to_string(),
        val: 12,
    };

    task::sleep(Duration::from_secs(1)).await;
    let mut stream = TcpStream::connect("127.0.0.1:3022").await.unwrap();
    stream.tx(&m).await.unwrap();
}
Commit count: 15

cargo fmt