@@ -582,6 +582,29 @@ where
582
582
Ok ( ( ) )
583
583
}
584
584
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
+
585
608
/// The `Read` trait allows for reading bytes from a source.
586
609
///
587
610
/// Implementors of the `Read` trait are called 'readers'.
@@ -978,24 +1001,8 @@ pub trait Read {
978
1001
///
979
1002
/// If this function returns an error, all bytes read will be appended to `cursor`.
980
1003
#[ 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)
999
1006
}
1000
1007
1001
1008
/// Creates a "by reference" adaptor for this instance of `Read`.
0 commit comments