finish BufRead

staging
dignifiedquire 5 years ago
parent dc6c8fb131
commit a1aa3f823d

@ -139,28 +139,26 @@ impl<T: Read + Unpin, U: Read + Unpin> Read for Chain<T, U> {
}
impl<T: BufRead + Unpin, U: BufRead + Unpin> BufRead for Chain<T, U> {
fn poll_fill_buf(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<&[u8]>> {
// FIXME: how to make this compile?
// let Self {
// first,
// second,
// done_first
// } = &mut *self;
// if !*done_first {
// let rd = Pin::new(first);
// match futures_core::ready!(rd.poll_fill_buf(cx)) {
// Ok(buf) if buf.is_empty() => { *done_first = true; }
// Ok(buf) => return Poll::Ready(Ok(buf)),
// Err(err) => return Poll::Ready(Err(err)),
// }
// }
// let rd = Pin::new(second);
// rd.poll_fill_buf(cx)
unimplemented!()
fn poll_fill_buf(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<&[u8]>> {
let Self {
first,
second,
done_first,
} = unsafe { self.get_unchecked_mut() };
if !*done_first {
let first = unsafe { Pin::new_unchecked(first) };
match futures_core::ready!(first.poll_fill_buf(cx)) {
Ok(buf) if buf.is_empty() => {
*done_first = true;
}
Ok(buf) => return Poll::Ready(Ok(buf)),
Err(err) => return Poll::Ready(Err(err)),
}
}
let second = unsafe { Pin::new_unchecked(second) };
second.poll_fill_buf(cx)
}
fn consume(mut self: Pin<&mut Self>, amt: usize) {

@ -187,28 +187,21 @@ pub fn take_read_internal<R: Read + ?Sized>(
}
impl<T: BufRead + Unpin> BufRead for Take<T> {
fn poll_fill_buf(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<&[u8]>> {
// FIXME: how to get this to compile?
unimplemented!();
// let Self {
// inner,
// limit,
// } = &mut *self;
// if *limit == 0 {
// return Poll::Ready(Ok(&[]));
// }
// let rd = Pin::new(inner);
// match futures_core::ready!(rd.poll_fill_buf(cx)) {
// Ok(buf) => {
// let cap = cmp::min(buf.len() as u64, *limit) as usize;
// Poll::Ready(Ok(&buf[..cap]))
// }
// Err(e) => Poll::Ready(Err(e)),
// }
fn poll_fill_buf(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<&[u8]>> {
let Self { inner, limit } = unsafe { self.get_unchecked_mut() };
let inner = unsafe { Pin::new_unchecked(inner) };
if *limit == 0 {
return Poll::Ready(Ok(&[]));
}
match futures_core::ready!(inner.poll_fill_buf(cx)) {
Ok(buf) => {
let cap = cmp::min(buf.len() as u64, *limit) as usize;
Poll::Ready(Ok(&buf[..cap]))
}
Err(e) => Poll::Ready(Err(e)),
}
}
fn consume(mut self: Pin<&mut Self>, amt: usize) {

Loading…
Cancel
Save