Function tokio::io::copy[][src]

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

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

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

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.

This is an asynchronous version of std::io::copy.

Errors

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

Examples

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