[][src]Function tokio::io::copy_buf

pub async fn copy_buf<'a, R: ?Sized, W: ?Sized>(
    reader: &'a mut R,
    writer: &'a mut W
) -> Result<u64> where
    R: AsyncBufRead + Unpin,
    W: AsyncWrite + Unpin
This is supported on crate feature io-util only.

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.

On success, the total number of bytes that were copied from reader to writer is returned.

Errors

The returned future will finish with an error will return an error immediately if any call to poll_fill_buf or poll_write returns an error.

Examples

use tokio::io;

let mut reader: &[u8] = b"hello";
let mut writer: Vec<u8> = vec![];

io::copy_buf(&mut reader, &mut writer).await?;

assert_eq!(b"hello", &writer[..]);