@@ -5,26 +5,21 @@ use std::io;
5
5
use std:: pin:: Pin ;
6
6
use std:: task:: { Context , Poll } ;
7
7
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
+ }
27
21
22
+ cfg_io_util ! {
28
23
/// Asynchronously copies the entire contents of a reader into a writer.
29
24
///
30
25
/// This function returns a future that will continuously read data from
@@ -58,7 +53,7 @@ cfg_io_util! {
58
53
/// # Ok(())
59
54
/// # }
60
55
/// ```
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 >
62
57
where
63
58
R : AsyncRead + Unpin + ?Sized ,
64
59
W : AsyncWrite + Unpin + ?Sized ,
@@ -71,7 +66,7 @@ cfg_io_util! {
71
66
pos: 0 ,
72
67
cap: 0 ,
73
68
buf: vec![ 0 ; 2048 ] . into_boxed_slice( ) ,
74
- }
69
+ } . await
75
70
}
76
71
}
77
72
@@ -124,14 +119,3 @@ where
124
119
}
125
120
}
126
121
}
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
- }
0 commit comments