pub async fn copy<'a, R, W>(reader: &'a mut R, writer: &'a mut W) -> Result<u64>where R: AsyncRead + Unpin + ?Sized, W: AsyncWrite + Unpin + ?Sized,
Asynchronously copies the entire contents of a reader into a writer.
This function returns a future that will continuously read data from
reader and then write it into
writer in a streaming fashion until
reader returns EOF or fails.
On success, the total number of bytes that were copied from
writer is returned.
This is an asynchronous version of
A heap-allocated copy buffer with 8 KB is created to take data from the
reader to the writer, check
copy_buf if you want an alternative for
AsyncBufRead. You can use
BufReader to change the
The returned future will return an error immediately if any call to
poll_write returns an error.
use tokio::io; let mut reader: &[u8] = b"hello"; let mut writer: Vec<u8> = vec!; io::copy(&mut reader, &mut writer).await?; assert_eq!(&b"hello"[..], &writer[..]);