File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -356,7 +356,7 @@ where
356356
357357 match result {
358358 Ok ( _) => self . pos += buf. len ( ) as u64 ,
359- // The only posible error condition is EOF
359+ // The only possible error condition is EOF, so place the cursor at "EOF"
360360 Err ( _) => self . pos = self . inner . as_ref ( ) . len ( ) as u64 ,
361361 }
362362
Original file line number Diff line number Diff line change @@ -653,6 +653,38 @@ fn test_take_wrong_length() {
653653 let _ = reader. read ( & mut buffer[ ..] ) ;
654654}
655655
656+ #[ test]
657+ fn slice_read_exact_eof ( ) {
658+ let slice = & b"123456" [ ..] ;
659+
660+ let mut r = slice;
661+ assert ! ( r. read_exact( & mut [ 0 ; 10 ] ) . is_err( ) ) ;
662+ assert ! ( r. is_empty( ) ) ;
663+
664+ let mut r = slice;
665+ let buf = & mut [ 0 ; 10 ] ;
666+ let mut buf = BorrowedBuf :: from ( buf. as_mut_slice ( ) ) ;
667+ assert ! ( r. read_buf_exact( buf. unfilled( ) ) . is_err( ) ) ;
668+ assert ! ( r. is_empty( ) ) ;
669+ assert_eq ! ( buf. filled( ) , b"123456" ) ;
670+ }
671+
672+ #[ test]
673+ fn cursor_read_exact_eof ( ) {
674+ let slice = Cursor :: new ( b"123456" ) ;
675+
676+ let mut r = slice. clone ( ) ;
677+ assert ! ( r. read_exact( & mut [ 0 ; 10 ] ) . is_err( ) ) ;
678+ assert ! ( r. is_empty( ) ) ;
679+
680+ let mut r = slice;
681+ let buf = & mut [ 0 ; 10 ] ;
682+ let mut buf = BorrowedBuf :: from ( buf. as_mut_slice ( ) ) ;
683+ assert ! ( r. read_buf_exact( buf. unfilled( ) ) . is_err( ) ) ;
684+ assert ! ( r. is_empty( ) ) ;
685+ assert_eq ! ( buf. filled( ) , b"123456" ) ;
686+ }
687+
656688#[ bench]
657689fn bench_take_read ( b : & mut test:: Bencher ) {
658690 b. iter ( || {
You can’t perform that action at this time.
0 commit comments