From 987ba7373cf95c570bf23768c6021f7a7508286e Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Sat, 26 Oct 2019 08:02:49 -0700 Subject: io: move into `tokio` crate (#1691) A step towards collapsing Tokio sub crates into a single `tokio` crate (#1318). The `io` implementation is now provided by the main `tokio` crate. Functionality can be opted out of by using the various net related feature flags. --- tokio/tests/io_read.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 tokio/tests/io_read.rs (limited to 'tokio/tests/io_read.rs') diff --git a/tokio/tests/io_read.rs b/tokio/tests/io_read.rs new file mode 100644 index 00000000..01cd2fd6 --- /dev/null +++ b/tokio/tests/io_read.rs @@ -0,0 +1,37 @@ +#![warn(rust_2018_idioms)] + +use tokio::io::{AsyncRead, AsyncReadExt}; +use tokio_test::assert_ok; + +use std::io; +use std::pin::Pin; +use std::task::{Context, Poll}; + +#[tokio::test] +async fn read() { + #[derive(Default)] + struct Rd { + poll_cnt: usize, + } + + impl AsyncRead for Rd { + fn poll_read( + mut self: Pin<&mut Self>, + _cx: &mut Context<'_>, + buf: &mut [u8], + ) -> Poll> { + assert_eq!(0, self.poll_cnt); + self.poll_cnt += 1; + + buf[0..11].copy_from_slice(b"hello world"); + Poll::Ready(Ok(11)) + } + } + + let mut buf = Box::new([0; 11]); + let mut rd = Rd::default(); + + let n = assert_ok!(rd.read(&mut buf[..]).await); + assert_eq!(n, 11); + assert_eq!(buf[..], b"hello world"[..]); +} -- cgit v1.2.3