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> { 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]>> { 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,
} = unsafe { self.get_unchecked_mut() };
// let Self { if !*done_first {
// first, let first = unsafe { Pin::new_unchecked(first) };
// second, match futures_core::ready!(first.poll_fill_buf(cx)) {
// done_first Ok(buf) if buf.is_empty() => {
// } = &mut *self; *done_first = true;
}
Ok(buf) => return Poll::Ready(Ok(buf)),
Err(err) => return Poll::Ready(Err(err)),
}
}
// if !*done_first { let second = unsafe { Pin::new_unchecked(second) };
// let rd = Pin::new(first); second.poll_fill_buf(cx)
// 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 consume(mut self: Pin<&mut Self>, amt: usize) { 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> { impl<T: BufRead + Unpin> BufRead for Take<T> {
fn poll_fill_buf(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<&[u8]>> { fn poll_fill_buf(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<&[u8]>> {
// FIXME: how to get this to compile? let Self { inner, limit } = unsafe { self.get_unchecked_mut() };
unimplemented!(); let inner = unsafe { Pin::new_unchecked(inner) };
// let Self { if *limit == 0 {
// inner, return Poll::Ready(Ok(&[]));
// limit, }
// } = &mut *self;
// if *limit == 0 { match futures_core::ready!(inner.poll_fill_buf(cx)) {
// return Poll::Ready(Ok(&[])); Ok(buf) => {
// } let cap = cmp::min(buf.len() as u64, *limit) as usize;
Poll::Ready(Ok(&buf[..cap]))
// let rd = Pin::new(inner); }
Err(e) => Poll::Ready(Err(e)),
// 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 consume(mut self: Pin<&mut Self>, amt: usize) { fn consume(mut self: Pin<&mut Self>, amt: usize) {