io-streams 0.16.3

Unbuffered and unlocked I/O streams
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
use io_streams::{StreamReader, StreamWriter};
use std::io::copy;

fn main() -> anyhow::Result<()> {
    #[cfg(not(target_os = "wasi"))] // WASI doesn't support pipes yet
    let mut input = StreamReader::str("hello world\n")?;

    #[cfg(target_os = "wasi")]
    let mut input = StreamReader::stdin()?;
    assert!(!cfg!(target_os = "wasi"), "WASI doesn't support pipes yet");

    let mut output = StreamWriter::stdout()?;
    copy(&mut input, &mut output)?;
    Ok(())
}