@@ -582,6 +582,29 @@ where
582582 Ok ( ( ) )
583583}
584584
585+ pub ( crate ) fn default_read_buf_exact < R : Read + ?Sized > (
586+ this : & mut R ,
587+ mut cursor : BorrowedCursor < ' _ > ,
588+ ) -> Result < ( ) > {
589+ while cursor. capacity ( ) > 0 {
590+ let prev_written = cursor. written ( ) ;
591+ match this. read_buf ( cursor. reborrow ( ) ) {
592+ Ok ( ( ) ) => { }
593+ Err ( e) if e. is_interrupted ( ) => continue ,
594+ Err ( e) => return Err ( e) ,
595+ }
596+
597+ if cursor. written ( ) == prev_written {
598+ return Err ( error:: const_io_error!(
599+ ErrorKind :: UnexpectedEof ,
600+ "failed to fill whole buffer"
601+ ) ) ;
602+ }
603+ }
604+
605+ Ok ( ( ) )
606+ }
607+
585608/// The `Read` trait allows for reading bytes from a source.
586609///
587610/// Implementors of the `Read` trait are called 'readers'.
@@ -978,24 +1001,8 @@ pub trait Read {
9781001 ///
9791002 /// If this function returns an error, all bytes read will be appended to `cursor`.
9801003 #[ unstable( feature = "read_buf" , issue = "78485" ) ]
981- fn read_buf_exact ( & mut self , mut cursor : BorrowedCursor < ' _ > ) -> Result < ( ) > {
982- while cursor. capacity ( ) > 0 {
983- let prev_written = cursor. written ( ) ;
984- match self . read_buf ( cursor. reborrow ( ) ) {
985- Ok ( ( ) ) => { }
986- Err ( e) if e. is_interrupted ( ) => continue ,
987- Err ( e) => return Err ( e) ,
988- }
989-
990- if cursor. written ( ) == prev_written {
991- return Err ( error:: const_io_error!(
992- ErrorKind :: UnexpectedEof ,
993- "failed to fill whole buffer"
994- ) ) ;
995- }
996- }
997-
998- Ok ( ( ) )
1004+ fn read_buf_exact ( & mut self , cursor : BorrowedCursor < ' _ > ) -> Result < ( ) > {
1005+ default_read_buf_exact ( self , cursor)
9991006 }
10001007
10011008 /// Creates a "by reference" adaptor for this instance of `Read`.
0 commit comments