wstd 0.5.0-draft2

An async standard library for Wasm Components and WASI 0.2
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use crate::io::{AsyncRead, AsyncWrite};

/// Copy bytes from a reader to a writer.
pub async fn copy<R, W>(mut reader: R, mut writer: W) -> crate::io::Result<()>
where
    R: AsyncRead,
    W: AsyncWrite,
{
    let mut buf = [0; 1024];
    'read: loop {
        let bytes_read = reader.read(&mut buf).await?;
        if bytes_read == 0 {
            break 'read Ok(());
        }
        writer.write_all(&buf[0..bytes_read]).await?;
    }
}