File tree 1 file changed +36
-1
lines changed
1 file changed +36
-1
lines changed Original file line number Diff line number Diff line change 1
1
use std:: cmp;
2
2
use std:: pin:: Pin ;
3
3
4
- use crate :: io:: { self , Read } ;
4
+ use crate :: io:: { self , BufRead , Read } ;
5
5
use crate :: task:: { Context , Poll } ;
6
6
7
7
/// Reader adaptor which limits the bytes read from an underlying reader.
@@ -186,6 +186,41 @@ pub fn take_read_internal<R: Read + ?Sized>(
186
186
}
187
187
}
188
188
189
+ impl < T : BufRead + Unpin > BufRead for Take < T > {
190
+ fn poll_fill_buf ( self : Pin < & mut Self > , _cx : & mut Context < ' _ > ) -> Poll < io:: Result < & [ u8 ] > > {
191
+ // FIXME: how to get this to compile?
192
+ unimplemented ! ( ) ;
193
+
194
+ // let Self {
195
+ // inner,
196
+ // limit,
197
+ // } = &mut *self;
198
+
199
+ // if *limit == 0 {
200
+ // return Poll::Ready(Ok(&[]));
201
+ // }
202
+
203
+ // let rd = Pin::new(inner);
204
+
205
+ // match futures_core::ready!(rd.poll_fill_buf(cx)) {
206
+ // Ok(buf) => {
207
+ // let cap = cmp::min(buf.len() as u64, *limit) as usize;
208
+ // Poll::Ready(Ok(&buf[..cap]))
209
+ // }
210
+ // Err(e) => Poll::Ready(Err(e)),
211
+ // }
212
+ }
213
+
214
+ fn consume ( mut self : Pin < & mut Self > , amt : usize ) {
215
+ // Don't let callers reset the limit by passing an overlarge value
216
+ let amt = cmp:: min ( amt as u64 , self . limit ) as usize ;
217
+ self . limit -= amt as u64 ;
218
+
219
+ let rd = Pin :: new ( & mut self . inner ) ;
220
+ rd. consume ( amt) ;
221
+ }
222
+ }
223
+
189
224
#[ cfg( test) ]
190
225
mod tests {
191
226
use crate :: io;
You can’t perform that action at this time.
0 commit comments