File tree 2 files changed +33
-1
lines changed
2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -356,7 +356,7 @@ where
356
356
357
357
match result {
358
358
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"
360
360
Err ( _) => self . pos = self . inner . as_ref ( ) . len ( ) as u64 ,
361
361
}
362
362
Original file line number Diff line number Diff line change @@ -653,6 +653,38 @@ fn test_take_wrong_length() {
653
653
let _ = reader. read ( & mut buffer[ ..] ) ;
654
654
}
655
655
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
+
656
688
#[ bench]
657
689
fn bench_take_read ( b : & mut test:: Bencher ) {
658
690
b. iter ( || {
You can’t perform that action at this time.
0 commit comments