File tree Expand file tree Collapse file tree 1 file changed +36
-1
lines changed Expand file tree Collapse file tree 1 file changed +36
-1
lines changed Original file line number Diff line number Diff line change 11use std:: cmp;
22use std:: pin:: Pin ;
33
4- use crate :: io:: { self , Read } ;
4+ use crate :: io:: { self , BufRead , Read } ;
55use crate :: task:: { Context , Poll } ;
66
77/// Reader adaptor which limits the bytes read from an underlying reader.
@@ -186,6 +186,41 @@ pub fn take_read_internal<R: Read + ?Sized>(
186186 }
187187}
188188
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+
189224#[ cfg( test) ]
190225mod tests {
191226 use crate :: io;
You can’t perform that action at this time.
0 commit comments