pub fn copy_buf<R, W>(reader: R, writer: &mut W) -> CopyBuf<'_, R, W>Notable traits for CopyBuf<'_, R, W>impl<R, W> Future for CopyBuf<'_, R, W>where
    R: AsyncBufRead,
    W: AsyncWrite + Unpin + ?Sized,
type Output = Result<u64, Error>;
where
    R: AsyncBufRead,
    W: AsyncWrite + Unpin + ?Sized,
Expand description

Creates a future which copies all the bytes from one object to another.

The returned future will copy all the bytes read from this AsyncBufRead into the writer specified. This future will only complete once the reader has hit EOF and all bytes have been written to and flushed from the writer provided.

On success the number of bytes is returned.

Examples

use futures::io::{self, AsyncWriteExt, Cursor};

let reader = Cursor::new([1, 2, 3, 4]);
let mut writer = Cursor::new(vec![0u8; 5]);

let bytes = io::copy_buf(reader, &mut writer).await?;
writer.close().await?;

assert_eq!(bytes, 4);
assert_eq!(writer.into_inner(), [1, 2, 3, 4, 0]);