1use crate::{AsyncRead, AsyncWrite, AsyncWriteExt, IoResult};
3
4mod bilock;
5
6mod take;
7pub use take::Take;
8
9mod null;
10pub use null::{Null, null};
11
12mod repeat;
13pub use repeat::{Repeat, repeat};
14
15mod internal;
16pub(crate) use internal::*;
17
18pub mod split;
19pub use split::Splittable;
20
21pub async fn copy<R: AsyncRead, W: AsyncWrite>(reader: &mut R, writer: &mut W) -> IoResult<u64> {
35 let mut buf = Vec::with_capacity(DEFAULT_BUF_SIZE);
36 let mut total = 0u64;
37
38 loop {
39 let res;
40 (res, buf) = reader.read(buf).await.into();
41 match res {
42 Ok(0) => break,
43 Ok(read) => {
44 total += read as u64;
45 }
46 Err(e) if e.kind() == std::io::ErrorKind::Interrupted => {
47 continue;
48 }
49 Err(e) => return Err(e),
50 }
51 let res;
52 (res, buf) = writer.write_all(buf).await.into();
53 res?;
54 buf.clear();
55 }
56
57 Ok(total)
58}