File tree 1 file changed +13
-0
lines changed 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -56,6 +56,9 @@ impl<T> BufReadExt for T where T: io::BufRead {
56
56
fn discard_exact ( & mut self , mut len : usize ) -> io:: Result < ( ) > {
57
57
while len > 0 {
58
58
let consume_len = match self . fill_buf ( ) {
59
+ Ok ( buf) if buf. is_empty ( ) =>
60
+ return Err ( io:: Error :: new (
61
+ io:: ErrorKind :: UnexpectedEof , "unexpected EOF" ) ) ,
59
62
Ok ( buf) => buf. len ( ) . min ( len) ,
60
63
Err ( e) if e. kind ( ) == io:: ErrorKind :: Interrupted => continue ,
61
64
Err ( e) => return Err ( e) ,
@@ -99,6 +102,16 @@ mod tests {
99
102
use std:: io:: Read ;
100
103
use super :: * ;
101
104
105
+ #[ test]
106
+ fn discard_exact ( ) {
107
+ let mut buf = b"abc" . as_ref ( ) ;
108
+ buf. discard_exact ( 1 ) . unwrap ( ) ;
109
+ assert_eq ! ( buf, b"bc" ) ;
110
+ buf. discard_exact ( 2 ) . unwrap ( ) ;
111
+ assert_eq ! ( buf, b"" ) ;
112
+ buf. discard_exact ( 1 ) . unwrap_err ( ) ;
113
+ }
114
+
102
115
#[ test]
103
116
fn read8_len ( ) {
104
117
let mut reader = Cursor :: new ( [ ] ) ;
You can’t perform that action at this time.
0 commit comments