2
0
Fork 1
mirror of https://github.com/async-rs/async-std.git synced 2025-02-28 15:19:41 +00:00

finish BufRead

This commit is contained in:
dignifiedquire 2019-09-27 18:59:30 +02:00
parent dc6c8fb131
commit a1aa3f823d
2 changed files with 31 additions and 40 deletions

View file

@ -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?
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() };
// let Self {
// first,
// second,
// done_first
// } = &mut *self;
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)),
}
}
// 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!()
let second = unsafe { Pin::new_unchecked(second) };
second.poll_fill_buf(cx)
}
fn consume(mut self: Pin<&mut Self>, amt: usize) {

View file

@ -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!();
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) };
// let Self {
// inner,
// limit,
// } = &mut *self;
if *limit == 0 {
return Poll::Ready(Ok(&[]));
}
// 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)),
// }
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) {