diff options
author | Sean McArthur <sean@seanmonstar.com> | 2020-08-13 20:15:01 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-13 20:15:01 -0700 |
commit | c393236dfd12c13e82badd631d3a3a90481c6f95 (patch) | |
tree | 47e7e70b7a58fb968870d5d44e95f6c45192e114 /tokio-util/tests/framed_read.rs | |
parent | 71da06097bf9aa851ebdde79d7b01a3e38174db9 (diff) |
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.
Diffstat (limited to 'tokio-util/tests/framed_read.rs')
-rw-r--r-- | tokio-util/tests/framed_read.rs | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/tokio-util/tests/framed_read.rs b/tokio-util/tests/framed_read.rs index 27bb298a..da38c432 100644 --- a/tokio-util/tests/framed_read.rs +++ b/tokio-util/tests/framed_read.rs @@ -1,6 +1,6 @@ #![warn(rust_2018_idioms)] -use tokio::io::AsyncRead; +use tokio::io::{AsyncRead, ReadBuf}; use tokio_test::assert_ready; use tokio_test::task; use tokio_util::codec::{Decoder, FramedRead}; @@ -264,19 +264,19 @@ impl AsyncRead for Mock { fn poll_read( mut self: Pin<&mut Self>, _cx: &mut Context<'_>, - buf: &mut [u8], - ) -> Poll<io::Result<usize>> { + buf: &mut ReadBuf<'_>, + ) -> Poll<io::Result<()>> { use io::ErrorKind::WouldBlock; match self.calls.pop_front() { Some(Ok(data)) => { - debug_assert!(buf.len() >= data.len()); - buf[..data.len()].copy_from_slice(&data[..]); - Ready(Ok(data.len())) + debug_assert!(buf.remaining() >= data.len()); + buf.append(&data); + Ready(Ok(())) } Some(Err(ref e)) if e.kind() == WouldBlock => Pending, Some(Err(e)) => Ready(Err(e)), - None => Ready(Ok(0)), + None => Ready(Ok(())), } } } @@ -288,8 +288,8 @@ impl AsyncRead for Slice<'_> { fn poll_read( mut self: Pin<&mut Self>, cx: &mut Context<'_>, - buf: &mut [u8], - ) -> Poll<io::Result<usize>> { + buf: &mut ReadBuf<'_>, + ) -> Poll<io::Result<()>> { Pin::new(&mut self.0).poll_read(cx, buf) } } |