Skip to content

Commit 41ac1ae

Browse files
authored
io: make Seek and Copy private (#2935)
Refs: #2928
1 parent 60d81bb commit 41ac1ae

File tree

3 files changed

+18
-35
lines changed

3 files changed

+18
-35
lines changed

tokio/src/io/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,11 @@ cfg_io_util! {
232232
pub use split::{split, ReadHalf, WriteHalf};
233233

234234
pub(crate) mod seek;
235-
pub use self::seek::Seek;
236235

237236
pub(crate) mod util;
238237
pub use util::{
239238
copy, duplex, empty, repeat, sink, AsyncBufReadExt, AsyncReadExt, AsyncSeekExt, AsyncWriteExt,
240-
BufReader, BufStream, BufWriter, DuplexStream, Copy, Empty, Lines, Repeat, Sink, Split, Take,
239+
BufReader, BufStream, BufWriter, DuplexStream, Empty, Lines, Repeat, Sink, Split, Take,
241240
};
242241
}
243242

tokio/src/io/util/copy.rs

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,21 @@ use std::io;
55
use std::pin::Pin;
66
use std::task::{Context, Poll};
77

8-
cfg_io_util! {
9-
/// A future that asynchronously copies the entire contents of a reader into a
10-
/// writer.
11-
///
12-
/// This struct is generally created by calling [`copy`][copy]. Please
13-
/// see the documentation of `copy()` for more details.
14-
///
15-
/// [copy]: copy()
16-
#[derive(Debug)]
17-
#[must_use = "futures do nothing unless you `.await` or poll them"]
18-
pub struct Copy<'a, R: ?Sized, W: ?Sized> {
19-
reader: &'a mut R,
20-
read_done: bool,
21-
writer: &'a mut W,
22-
pos: usize,
23-
cap: usize,
24-
amt: u64,
25-
buf: Box<[u8]>,
26-
}
8+
/// A future that asynchronously copies the entire contents of a reader into a
9+
/// writer.
10+
#[derive(Debug)]
11+
#[must_use = "futures do nothing unless you `.await` or poll them"]
12+
struct Copy<'a, R: ?Sized, W: ?Sized> {
13+
reader: &'a mut R,
14+
read_done: bool,
15+
writer: &'a mut W,
16+
pos: usize,
17+
cap: usize,
18+
amt: u64,
19+
buf: Box<[u8]>,
20+
}
2721

22+
cfg_io_util! {
2823
/// Asynchronously copies the entire contents of a reader into a writer.
2924
///
3025
/// This function returns a future that will continuously read data from
@@ -58,7 +53,7 @@ cfg_io_util! {
5853
/// # Ok(())
5954
/// # }
6055
/// ```
61-
pub fn copy<'a, R, W>(reader: &'a mut R, writer: &'a mut W) -> Copy<'a, R, W>
56+
pub async fn copy<'a, R, W>(reader: &'a mut R, writer: &'a mut W) -> io::Result<u64>
6257
where
6358
R: AsyncRead + Unpin + ?Sized,
6459
W: AsyncWrite + Unpin + ?Sized,
@@ -71,7 +66,7 @@ cfg_io_util! {
7166
pos: 0,
7267
cap: 0,
7368
buf: vec![0; 2048].into_boxed_slice(),
74-
}
69+
}.await
7570
}
7671
}
7772

@@ -124,14 +119,3 @@ where
124119
}
125120
}
126121
}
127-
128-
#[cfg(test)]
129-
mod tests {
130-
use super::*;
131-
132-
#[test]
133-
fn assert_unpin() {
134-
use std::marker::PhantomPinned;
135-
crate::is_unpin::<Copy<'_, PhantomPinned, PhantomPinned>>();
136-
}
137-
}

tokio/src/io/util/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ cfg_io_util! {
2525
mod chain;
2626

2727
mod copy;
28-
pub use copy::{copy, Copy};
28+
pub use copy::copy;
2929

3030
mod empty;
3131
pub use empty::{empty, Empty};

0 commit comments

Comments
 (0)