async_flow/tokio/
stdout.rs

1// This is free and unencumbered software released into the public domain.
2
3use super::Inputs;
4use crate::io::Result;
5use alloc::string::ToString;
6
7pub async fn stdout<T: ToString>(mut inputs: Inputs<T>) -> Result {
8    use tokio::io::AsyncWriteExt;
9
10    let mut output = tokio::io::stdout();
11
12    while let Some(input) = inputs.recv().await? {
13        let mut line = input.to_string();
14        if !line.ends_with('\n') {
15            line.push('\n');
16        }
17        output.write_all(line.as_bytes()).await?;
18        output.flush().await?;
19    }
20
21    Ok(())
22}