1use async_std::prelude::*;
2use async_std::{io, task};
3use simple_message_channels::{Message, Reader};
4
5fn main() {
6 task::block_on(async move {
7 match recv().await {
8 Err(e) => eprintln!("Error: {:?}", e),
9 Ok(()) => eprintln!("Ok."),
10 }
11 });
12}
13
14async fn recv() -> Result<(), io::Error> {
15 let stdin = io::stdin().lock().await;
16 let mut reader = Reader::new(stdin);
17 while let Some(msg) = reader.next().await {
18 let msg = msg?;
19 print_msg(&msg);
20 }
21 Ok(())
22}
23
24fn print_msg(msg: &Message) {
25 let text = String::from_utf8(msg.message.clone()).unwrap();
26 eprintln!("recv: ch {} typ {}: {}", msg.channel, msg.typ, text);
27}