File tree Expand file tree Collapse file tree 2 files changed +12
-9
lines changed Expand file tree Collapse file tree 2 files changed +12
-9
lines changed Original file line number Diff line number Diff line change 12
12
if bytes_read == 0 {
13
13
break ' read Ok ( ( ) ) ;
14
14
}
15
- let mut slice = & buf[ 0 ..bytes_read] ;
16
-
17
- ' write: loop {
18
- let bytes_written = writer. write ( slice) . await ?;
19
- slice = & slice[ bytes_written..] ;
20
- if slice. is_empty ( ) {
21
- break ' write;
22
- }
23
- }
15
+ writer. write_all ( & buf[ 0 ..bytes_read] ) . await ?;
24
16
}
25
17
}
Original file line number Diff line number Diff line change @@ -5,4 +5,15 @@ pub trait AsyncWrite {
5
5
// Required methods
6
6
async fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > ;
7
7
async fn flush ( & mut self ) -> io:: Result < ( ) > ;
8
+
9
+ async fn write_all ( & mut self , buf : & [ u8 ] ) -> io:: Result < ( ) > {
10
+ let mut to_write = & buf[ 0 ..] ;
11
+ loop {
12
+ let bytes_written = self . write ( to_write) . await ?;
13
+ to_write = & to_write[ bytes_written..] ;
14
+ if to_write. is_empty ( ) {
15
+ return Ok ( ( ) ) ;
16
+ }
17
+ }
18
+ }
8
19
}
You can’t perform that action at this time.
0 commit comments