io: change AsyncRead to use a ReadBuf (#2758)

Works towards #2716. Changes the argument to `AsyncRead::poll_read` to
take a `ReadBuf` struct that safely manages writes to uninitialized memory.
This commit is contained in:
Sean McArthur
2020-08-13 20:15:01 -07:00
committed by GitHub
parent 71da06097b
commit c393236dfd
40 changed files with 626 additions and 544 deletions
+5 -4
View File
@@ -1,7 +1,7 @@
#![warn(rust_2018_idioms)]
#![cfg(feature = "full")]
use tokio::io::{split, AsyncRead, AsyncWrite, ReadHalf, WriteHalf};
use tokio::io::{split, AsyncRead, AsyncWrite, ReadBuf, ReadHalf, WriteHalf};
use std::io;
use std::pin::Pin;
@@ -13,9 +13,10 @@ impl AsyncRead for RW {
fn poll_read(
self: Pin<&mut Self>,
_cx: &mut Context<'_>,
_buf: &mut [u8],
) -> Poll<io::Result<usize>> {
Poll::Ready(Ok(1))
buf: &mut ReadBuf<'_>,
) -> Poll<io::Result<()>> {
buf.append(&[b'z']);
Poll::Ready(Ok(()))
}
}