Function copy

Source
pub fn copy<R, W, F>(reader: R, writer: W, report_progress: F) -> Copy<R, W, F> 
where R: AsyncBufRead, W: AsyncWrite, F: FnMut(u64),
Expand description

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

The returned future will copy all the bytes read from reader into the writer specified. After each write, report_progress is called with the current amount of copied bytes. 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.


§Errors

This function will return an error immediately if any call to poll_fill_buf, poll_write or poll_flush returns an error.


§Example

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

let progress = AtomicU64::new(0);
let report_progress = |amt| progress.store(amt, Ordering::Relaxed);

async_copy_progress::copy(&mut reader, &mut writer, report_progress).await?;

assert_eq!(&b"hello"[..], &writer[..]);
assert_eq!(5, progress.load(Ordering::Relaxed));