File tree Expand file tree Collapse file tree 3 files changed +12
-2
lines changed
futures-util/src/try_stream Expand file tree Collapse file tree 3 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -139,6 +139,8 @@ where
139
139
mut self : Pin < & mut Self > ,
140
140
amount : usize ,
141
141
) {
142
+ // https://github.com/rust-lang-nursery/futures-rs/pull/1556#discussion_r281644295
143
+ if amount == 0 { return }
142
144
if let ReadState :: Ready { chunk, chunk_start } = & mut self . state {
143
145
* chunk_start += amount;
144
146
debug_assert ! ( * chunk_start <= chunk. as_ref( ) . len( ) ) ;
Original file line number Diff line number Diff line change 1
1
use futures:: executor:: block_on;
2
2
use futures:: future:: Future ;
3
+ use futures:: stream:: { self , StreamExt , TryStreamExt } ;
3
4
use futures:: io:: AsyncBufReadExt ;
4
5
use futures:: task:: Poll ;
5
6
use futures_test:: io:: AsyncReadTestExt ;
@@ -42,7 +43,10 @@ fn maybe_pending() {
42
43
assert_eq ! ( run( buf. read_line( & mut v) ) . unwrap( ) , 2 ) ;
43
44
assert_eq ! ( v, "12" ) ;
44
45
45
- let mut buf = b"12\n \n " . interleave_pending ( ) ;
46
+ let mut buf = stream:: iter ( vec ! [ & b"12" [ ..] , & b"\n \n " [ ..] ] )
47
+ . map ( Ok )
48
+ . into_async_read ( )
49
+ . interleave_pending ( ) ;
46
50
let mut v = String :: new ( ) ;
47
51
assert_eq ! ( run( buf. read_line( & mut v) ) . unwrap( ) , 3 ) ;
48
52
assert_eq ! ( v, "12\n " ) ;
Original file line number Diff line number Diff line change 1
1
use futures:: executor:: block_on;
2
2
use futures:: future:: Future ;
3
+ use futures:: stream:: { self , StreamExt , TryStreamExt } ;
3
4
use futures:: io:: AsyncBufReadExt ;
4
5
use futures:: task:: Poll ;
5
6
use futures_test:: io:: AsyncReadTestExt ;
@@ -42,7 +43,10 @@ fn maybe_pending() {
42
43
assert_eq ! ( run( buf. read_until( b'3' , & mut v) ) . unwrap( ) , 2 ) ;
43
44
assert_eq ! ( v, b"12" ) ;
44
45
45
- let mut buf = b"12333" . interleave_pending ( ) ;
46
+ let mut buf = stream:: iter ( vec ! [ & b"12" [ ..] , & b"33" [ ..] , & b"3" [ ..] ] )
47
+ . map ( Ok )
48
+ . into_async_read ( )
49
+ . interleave_pending ( ) ;
46
50
let mut v = Vec :: new ( ) ;
47
51
assert_eq ! ( run( buf. read_until( b'3' , & mut v) ) . unwrap( ) , 3 ) ;
48
52
assert_eq ! ( v, b"123" ) ;
You can’t perform that action at this time.
0 commit comments