mod take;
pub use take::Take;
mod null;
pub use null::{Null, null};
mod repeat;
pub use repeat::{Repeat, repeat};
mod internal;
pub(crate) use internal::*;
use crate::{AsyncRead, AsyncWrite, AsyncWriteExt, IoResult};
pub async fn copy<R: AsyncRead, W: AsyncWrite>(reader: &mut R, writer: &mut W) -> IoResult<u64> {
let mut buf = Vec::with_capacity(DEFAULT_BUF_SIZE);
let mut total = 0u64;
loop {
let res;
(res, buf) = reader.read(buf).await.into();
match res {
Ok(0) => break,
Ok(read) => {
total += read as u64;
}
Err(e) if e.kind() == std::io::ErrorKind::Interrupted => {
continue;
}
Err(e) => return Err(e),
}
let res;
(res, buf) = writer.write_all(buf).await.into();
res?;
buf.clear();
}
Ok(total)
}