@@ -390,6 +390,28 @@ fn read_to_end_with_reservation<R: Read + ?Sized>(r: &mut R,
390390 ret
391391}
392392
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+
393415/// The `Read` trait allows for reading bytes from a source.
394416///
395417/// Implementors of the `Read` trait are called 'readers'.
@@ -528,14 +550,11 @@ pub trait Read {
528550 /// written to possibly being only partially filled. This method must behave
529551 /// as a single call to `read` with the buffers concatenated would.
530552 ///
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 .
533555 #[ unstable( feature = "iovec" , issue = "58452" ) ]
534556 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)
539558 }
540559
541560 /// Determines if this `Read`er can work with buffers of uninitialized
@@ -1107,14 +1126,11 @@ pub trait Write {
11071126 /// read from possibly being only partially consumed. This method must
11081127 /// behave as a call to `write` with the buffers concatenated would.
11091128 ///
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 .
11121131 #[ unstable( feature = "iovec" , issue = "58452" ) ]
11131132 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)
11181134 }
11191135
11201136 /// Flush this output stream, ensuring that all intermediately buffered
0 commit comments