qcomms is a small library that offers a simple message passing trait. it also offers keepalive and other stream helpers.
```rust use qcomms::ObjComms; use serde::{Serialize, Deserialize}; use asyncstd::task; use asyncstd::task::sleep; use async_std::net::{TcpListener, TcpStream};
pub struct Message { hello: String, val: u32, }
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();
} ```