@@ -390,6 +390,28 @@ fn read_to_end_with_reservation<R: Read + ?Sized>(r: &mut R,
390
390
ret
391
391
}
392
392
393
+ pub ( crate ) fn default_read_vectored < F > ( read : F , bufs : & mut [ IoVecMut < ' _ > ] ) -> Result < usize >
394
+ where
395
+ F : FnOnce ( & mut [ u8 ] ) -> Result < usize >
396
+ {
397
+ let buf = bufs
398
+ . iter_mut ( )
399
+ . find ( |b| !b. is_empty ( ) )
400
+ . map_or ( & mut [ ] [ ..] , |b| & mut * * b) ;
401
+ read ( buf)
402
+ }
403
+
404
+ pub ( crate ) fn default_write_vectored < F > ( write : F , bufs : & [ IoVec < ' _ > ] ) -> Result < usize >
405
+ where
406
+ F : FnOnce ( & [ u8 ] ) -> Result < usize >
407
+ {
408
+ let buf = bufs
409
+ . iter ( )
410
+ . find ( |b| !b. is_empty ( ) )
411
+ . map_or ( & [ ] [ ..] , |b| & * * b) ;
412
+ write ( buf)
413
+ }
414
+
393
415
/// The `Read` trait allows for reading bytes from a source.
394
416
///
395
417
/// Implementors of the `Read` trait are called 'readers'.
@@ -528,14 +550,11 @@ pub trait Read {
528
550
/// written to possibly being only partially filled. This method must behave
529
551
/// as a single call to `read` with the buffers concatenated would.
530
552
///
531
- /// The default implementation simply passes the first nonempty buffer to
532
- /// `read` .
553
+ /// The default implementation calls `read` with either the first nonempty
554
+ /// buffer provided, or an empty one if none exists .
533
555
#[ unstable( feature = "iovec" , issue = "58452" ) ]
534
556
fn read_vectored ( & mut self , bufs : & mut [ IoVecMut < ' _ > ] ) -> Result < usize > {
535
- match bufs. iter_mut ( ) . find ( |b| !b. is_empty ( ) ) {
536
- Some ( buf) => self . read ( buf) ,
537
- None => Ok ( 0 ) ,
538
- }
557
+ default_read_vectored ( |b| self . read ( b) , bufs)
539
558
}
540
559
541
560
/// Determines if this `Read`er can work with buffers of uninitialized
@@ -1107,14 +1126,11 @@ pub trait Write {
1107
1126
/// read from possibly being only partially consumed. This method must
1108
1127
/// behave as a call to `write` with the buffers concatenated would.
1109
1128
///
1110
- /// The default implementation simply passes the first nonempty buffer to
1111
- /// `write` .
1129
+ /// The default implementation calls `write` with either the first nonempty
1130
+ /// buffer provided, or an empty one if none exists .
1112
1131
#[ unstable( feature = "iovec" , issue = "58452" ) ]
1113
1132
fn write_vectored ( & mut self , bufs : & [ IoVec < ' _ > ] ) -> Result < usize > {
1114
- match bufs. iter ( ) . find ( |b| !b. is_empty ( ) ) {
1115
- Some ( buf) => self . write ( buf) ,
1116
- None => Ok ( 0 ) ,
1117
- }
1133
+ default_write_vectored ( |b| self . write ( b) , bufs)
1118
1134
}
1119
1135
1120
1136
/// Flush this output stream, ensuring that all intermediately buffered
0 commit comments