[][src]Function futures_util::io::copy_buf

pub fn copy_buf<R, W: ?Sized>(reader: R, writer: &mut W) -> CopyBuf<'_, R, W>

Notable traits for CopyBuf<'_, R, W>

impl<R, W: ?Sized, '_> Future for CopyBuf<'_, R, W> where
    R: AsyncBufRead,
    W: AsyncWrite + Unpin
type Output = Result<u64>;
where
    R: AsyncBufRead,
    W: AsyncWrite + Unpin
This is supported on crate feature io only.

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]);