[][src]Function futures_util::io::copy

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

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

impl<R: AsyncRead, W: AsyncWrite + Unpin + ?Sized> Future for Copy<'_, R, W> type Output = Result<u64>;
where
    R: AsyncRead,
    W: AsyncWrite + Unpin

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

The returned future will copy all the bytes read from this AsyncRead 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(reader, &mut writer).await?;
writer.close().await?;

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