diff --git a/futures-io/src/lib.rs b/futures-io/src/lib.rs index 7ce07cef07..adb3aa3194 100644 --- a/futures-io/src/lib.rs +++ b/futures-io/src/lib.rs @@ -385,10 +385,6 @@ mod if_std { delegate_async_read_to_stdio!(); } - impl + Unpin> AsyncRead for io::Cursor { - delegate_async_read_to_stdio!(); - } - macro_rules! deref_async_write { () => { fn poll_write(mut self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8]) @@ -471,22 +467,6 @@ mod if_std { } } - impl AsyncWrite for io::Cursor<&mut [u8]> { - delegate_async_write_to_stdio!(); - } - - impl AsyncWrite for io::Cursor<&mut Vec> { - delegate_async_write_to_stdio!(); - } - - impl AsyncWrite for io::Cursor> { - delegate_async_write_to_stdio!(); - } - - impl AsyncWrite for io::Cursor> { - delegate_async_write_to_stdio!(); - } - impl AsyncWrite for Vec { delegate_async_write_to_stdio!(); } @@ -521,20 +501,6 @@ mod if_std { } } - macro_rules! delegate_async_seek_to_stdio { - () => { - fn poll_seek(mut self: Pin<&mut Self>, _: &mut Context<'_>, pos: SeekFrom) - -> Poll> - { - Poll::Ready(io::Seek::seek(&mut *self, pos)) - } - } - } - - impl + Unpin> AsyncSeek for io::Cursor { - delegate_async_seek_to_stdio!(); - } - macro_rules! deref_async_buf_read { () => { fn poll_fill_buf(self: Pin<&mut Self>, cx: &mut Context<'_>) @@ -590,10 +556,6 @@ mod if_std { impl AsyncBufRead for &[u8] { delegate_async_buf_read_to_stdio!(); } - - impl + Unpin> AsyncBufRead for io::Cursor { - delegate_async_buf_read_to_stdio!(); - } } #[cfg(feature = "std")] diff --git a/futures-test/src/io/read/mod.rs b/futures-test/src/io/read/mod.rs index b24a20e520..f6c51fd799 100644 --- a/futures-test/src/io/read/mod.rs +++ b/futures-test/src/io/read/mod.rs @@ -14,12 +14,12 @@ pub trait AsyncReadTestExt: AsyncRead { /// /// ``` /// use futures::task::Poll; - /// use futures::io::AsyncRead; + /// use futures::io::{AsyncRead, Cursor}; /// use futures_test::task::noop_context; /// use futures_test::io::AsyncReadTestExt; /// use futures::pin_mut; /// - /// let reader = std::io::Cursor::new(&[1, 2, 3]).interleave_pending(); + /// let reader = Cursor::new(&[1, 2, 3]).interleave_pending(); /// pin_mut!(reader); /// /// let mut cx = noop_context(); @@ -44,12 +44,12 @@ pub trait AsyncReadTestExt: AsyncRead { /// /// ``` /// use futures::task::Poll; - /// use futures::io::AsyncBufRead; + /// use futures::io::{AsyncBufRead, Cursor}; /// use futures_test::task::noop_context; /// use futures_test::io::AsyncReadTestExt; /// use futures::pin_mut; /// - /// let reader = std::io::Cursor::new(&[1, 2, 3]).interleave_pending(); + /// let reader = Cursor::new(&[1, 2, 3]).interleave_pending(); /// pin_mut!(reader); /// /// let mut cx = noop_context(); @@ -78,12 +78,12 @@ pub trait AsyncReadTestExt: AsyncRead { /// /// ``` /// use futures::task::Poll; - /// use futures::io::AsyncRead; + /// use futures::io::{AsyncRead, Cursor}; /// use futures_test::task::noop_context; /// use futures_test::io::AsyncReadTestExt; /// use futures::pin_mut; /// - /// let reader = std::io::Cursor::new(&[1, 2, 3, 4, 5]).limited(2); + /// let reader = Cursor::new(&[1, 2, 3, 4, 5]).limited(2); /// pin_mut!(reader); /// /// let mut cx = noop_context(); diff --git a/futures-test/src/io/write/mod.rs b/futures-test/src/io/write/mod.rs index c94d8541dc..d228dd6a77 100644 --- a/futures-test/src/io/write/mod.rs +++ b/futures-test/src/io/write/mod.rs @@ -14,12 +14,12 @@ pub trait AsyncWriteTestExt: AsyncWrite { /// /// ``` /// use futures::task::Poll; - /// use futures::io::AsyncWrite; + /// use futures::io::{AsyncWrite, Cursor}; /// use futures_test::task::noop_context; /// use futures_test::io::AsyncWriteTestExt; /// use futures::pin_mut; /// - /// let writer = std::io::Cursor::new(vec![0u8; 4].into_boxed_slice()).interleave_pending_write(); + /// let writer = Cursor::new(vec![0u8; 4].into_boxed_slice()).interleave_pending_write(); /// pin_mut!(writer); /// /// let mut cx = noop_context(); @@ -54,12 +54,12 @@ pub trait AsyncWriteTestExt: AsyncWrite { /// /// ``` /// use futures::task::Poll; - /// use futures::io::AsyncWrite; + /// use futures::io::{AsyncWrite, Cursor}; /// use futures_test::task::noop_context; /// use futures_test::io::AsyncWriteTestExt; /// use futures::pin_mut; /// - /// let writer = std::io::Cursor::new(vec![0u8; 4].into_boxed_slice()).limited_write(2); + /// let writer = Cursor::new(vec![0u8; 4].into_boxed_slice()).limited_write(2); /// pin_mut!(writer); /// /// let mut cx = noop_context(); diff --git a/futures-util/src/io/cursor.rs b/futures-util/src/io/cursor.rs new file mode 100644 index 0000000000..d1359231c5 --- /dev/null +++ b/futures-util/src/io/cursor.rs @@ -0,0 +1,238 @@ +use futures_core::task::{Context, Poll}; +#[cfg(feature = "read_initializer")] +use futures_io::Initializer; +use futures_io::{AsyncBufRead, AsyncRead, AsyncSeek, AsyncWrite, IoSlice, IoSliceMut, SeekFrom}; +use std::io; +use std::pin::Pin; + +/// A `Cursor` wraps an in-memory buffer and provides it with a +/// [`AsyncSeek`] implementation. +/// +/// `Cursor`s are used with in-memory buffers, anything implementing +/// `AsRef<[u8]>`, to allow them to implement [`AsyncRead`] and/or [`AsyncWrite`], +/// allowing these buffers to be used anywhere you might use a reader or writer +/// that does actual I/O. +/// +/// The standard library implements some I/O traits on various types which +/// are commonly used as a buffer, like `Cursor<`[`Vec`]`>` and +/// `Cursor<`[`&[u8]`][bytes]`>`. +/// +/// [`AsyncSeek`]: trait.AsyncSeek.html +/// [`AsyncRead`]: trait.AsyncRead.html +/// [`AsyncWrite`]: trait.AsyncWrite.html +/// [bytes]: https://doc.rust-lang.org/std/primitive.slice.html +#[derive(Clone, Debug, Default)] +pub struct Cursor { + inner: io::Cursor, +} + +impl Cursor { + /// Creates a new cursor wrapping the provided underlying in-memory buffer. + /// + /// Cursor initial position is `0` even if underlying buffer (e.g., `Vec`) + /// is not empty. So writing to cursor starts with overwriting `Vec` + /// content, not with appending to it. + /// + /// # Examples + /// + /// ``` + /// use futures::io::Cursor; + /// + /// let buff = Cursor::new(Vec::new()); + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// ``` + pub fn new(inner: T) -> Cursor { + Cursor { + inner: io::Cursor::new(inner), + } + } + + /// Consumes this cursor, returning the underlying value. + /// + /// # Examples + /// + /// ``` + /// use futures::io::Cursor; + /// + /// let buff = Cursor::new(Vec::new()); + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// + /// let vec = buff.into_inner(); + /// ``` + pub fn into_inner(self) -> T { + self.inner.into_inner() + } + + /// Gets a reference to the underlying value in this cursor. + /// + /// # Examples + /// + /// ``` + /// use futures::io::Cursor; + /// + /// let buff = Cursor::new(Vec::new()); + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// + /// let reference = buff.get_ref(); + /// ``` + pub fn get_ref(&self) -> &T { + self.inner.get_ref() + } + + /// Gets a mutable reference to the underlying value in this cursor. + /// + /// Care should be taken to avoid modifying the internal I/O state of the + /// underlying value as it may corrupt this cursor's position. + /// + /// # Examples + /// + /// ``` + /// use futures::io::Cursor; + /// + /// let mut buff = Cursor::new(Vec::new()); + /// # fn force_inference(_: &Cursor>) {} + /// # force_inference(&buff); + /// + /// let reference = buff.get_mut(); + /// ``` + pub fn get_mut(&mut self) -> &mut T { + self.inner.get_mut() + } + + /// Returns the current position of this cursor. + /// + /// # Examples + /// + /// ``` + /// # futures::executor::block_on(async { + /// use futures::io::{AsyncSeekExt, Cursor, SeekFrom}; + /// + /// let mut buff = Cursor::new(vec![1, 2, 3, 4, 5]); + /// + /// assert_eq!(buff.position(), 0); + /// + /// buff.seek(SeekFrom::Current(2)).await?; + /// assert_eq!(buff.position(), 2); + /// + /// buff.seek(SeekFrom::Current(-1)).await?; + /// assert_eq!(buff.position(), 1); + /// # Ok::<(), Box>(()) }).unwrap(); + /// ``` + pub fn position(&self) -> u64 { + self.inner.position() + } + + /// Sets the position of this cursor. + /// + /// # Examples + /// + /// ``` + /// use futures::io::Cursor; + /// + /// let mut buff = Cursor::new(vec![1, 2, 3, 4, 5]); + /// + /// assert_eq!(buff.position(), 0); + /// + /// buff.set_position(2); + /// assert_eq!(buff.position(), 2); + /// + /// buff.set_position(4); + /// assert_eq!(buff.position(), 4); + /// ``` + pub fn set_position(&mut self, pos: u64) { + self.inner.set_position(pos) + } +} + +impl AsyncSeek for Cursor +where + T: AsRef<[u8]> + Unpin, +{ + fn poll_seek( + mut self: Pin<&mut Self>, + _: &mut Context<'_>, + pos: SeekFrom, + ) -> Poll> { + Poll::Ready(io::Seek::seek(&mut self.inner, pos)) + } +} + +impl + Unpin> AsyncRead for Cursor { + #[cfg(feature = "read_initializer")] + #[inline] + unsafe fn initializer(&self) -> Initializer { + io::Read::initializer(&self.inner) + } + + fn poll_read( + mut self: Pin<&mut Self>, + _cx: &mut Context<'_>, + buf: &mut [u8], + ) -> Poll> { + Poll::Ready(io::Read::read(&mut self.inner, buf)) + } + + fn poll_read_vectored( + mut self: Pin<&mut Self>, + _: &mut Context<'_>, + bufs: &mut [IoSliceMut<'_>], + ) -> Poll> { + Poll::Ready(io::Read::read_vectored(&mut self.inner, bufs)) + } +} + +impl AsyncBufRead for Cursor +where + T: AsRef<[u8]> + Unpin, +{ + fn poll_fill_buf(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll> { + Poll::Ready(io::BufRead::fill_buf(&mut self.get_mut().inner)) + } + + fn consume(mut self: Pin<&mut Self>, amt: usize) { + io::BufRead::consume(&mut self.inner, amt) + } +} + +macro_rules! delegate_async_write_to_stdio { + () => { + fn poll_write(mut self: Pin<&mut Self>, _: &mut Context<'_>, buf: &[u8]) + -> Poll> + { + Poll::Ready(io::Write::write(&mut self.inner, buf)) + } + + fn poll_write_vectored(mut self: Pin<&mut Self>, _: &mut Context<'_>, bufs: &[IoSlice<'_>]) + -> Poll> + { + Poll::Ready(io::Write::write_vectored(&mut self.inner, bufs)) + } + + fn poll_flush(mut self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll> { + Poll::Ready(io::Write::flush(&mut self.inner)) + } + + fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { + self.poll_flush(cx) + } + } +} + +impl AsyncWrite for Cursor<&mut [u8]> { + delegate_async_write_to_stdio!(); +} + +impl AsyncWrite for Cursor<&mut Vec> { + delegate_async_write_to_stdio!(); +} + +impl AsyncWrite for Cursor> { + delegate_async_write_to_stdio!(); +} + +impl AsyncWrite for Cursor> { + delegate_async_write_to_stdio!(); +} diff --git a/futures-util/src/io/mod.rs b/futures-util/src/io/mod.rs index 74af2f719d..3c00b3f0cc 100644 --- a/futures-util/src/io/mod.rs +++ b/futures-util/src/io/mod.rs @@ -59,6 +59,9 @@ pub use self::copy_into::CopyInto; mod copy_buf_into; pub use self::copy_buf_into::CopyBufInto; +mod cursor; +pub use self::cursor::Cursor; + mod empty; pub use self::empty::{empty, Empty}; @@ -133,8 +136,7 @@ pub trait AsyncReadExt: AsyncRead { /// /// ``` /// # futures::executor::block_on(async { - /// use futures::io::AsyncReadExt; - /// use std::io::Cursor; + /// use futures::io::{AsyncReadExt, Cursor}; /// /// let reader1 = Cursor::new([1, 2, 3, 4]); /// let reader2 = Cursor::new([5, 6, 7, 8]); @@ -168,8 +170,7 @@ pub trait AsyncReadExt: AsyncRead { /// /// ``` /// # futures::executor::block_on(async { - /// use futures::io::{AsyncReadExt, AsyncWriteExt}; - /// use std::io::Cursor; + /// use futures::io::{AsyncReadExt, AsyncWriteExt, Cursor}; /// /// let reader = Cursor::new([1, 2, 3, 4]); /// let mut writer = Cursor::new(vec![0u8; 5]); @@ -199,8 +200,7 @@ pub trait AsyncReadExt: AsyncRead { /// /// ``` /// # futures::executor::block_on(async { - /// use futures::io::AsyncReadExt; - /// use std::io::Cursor; + /// use futures::io::{AsyncReadExt, Cursor}; /// /// let mut reader = Cursor::new([1, 2, 3, 4]); /// let mut output = [0u8; 5]; @@ -243,8 +243,7 @@ pub trait AsyncReadExt: AsyncRead { /// /// ``` /// # futures::executor::block_on(async { - /// use futures::io::AsyncReadExt; - /// use std::io::Cursor; + /// use futures::io::{AsyncReadExt, Cursor}; /// /// let mut reader = Cursor::new([1, 2, 3, 4]); /// let mut output = [0u8; 4]; @@ -259,8 +258,7 @@ pub trait AsyncReadExt: AsyncRead { /// /// ``` /// # futures::executor::block_on(async { - /// use futures::io::AsyncReadExt; - /// use std::io::{self, Cursor}; + /// use futures::io::{self, AsyncReadExt, Cursor}; /// /// let mut reader = Cursor::new([1, 2, 3, 4]); /// let mut output = [0u8; 5]; @@ -287,8 +285,7 @@ pub trait AsyncReadExt: AsyncRead { /// /// ``` /// # futures::executor::block_on(async { - /// use futures::io::AsyncReadExt; - /// use std::io::Cursor; + /// use futures::io::{AsyncReadExt, Cursor}; /// /// let mut reader = Cursor::new([1, 2, 3, 4]); /// let mut output = Vec::with_capacity(4); @@ -316,8 +313,7 @@ pub trait AsyncReadExt: AsyncRead { /// /// ``` /// # futures::executor::block_on(async { - /// use futures::io::AsyncReadExt; - /// use std::io::Cursor; + /// use futures::io::{AsyncReadExt, Cursor}; /// /// let mut reader = Cursor::new(&b"1234"[..]); /// let mut buffer = String::with_capacity(4); @@ -346,8 +342,7 @@ pub trait AsyncReadExt: AsyncRead { /// /// ``` /// # futures::executor::block_on(async { - /// use futures::io::AsyncReadExt; - /// use std::io::Cursor; + /// use futures::io::{AsyncReadExt, Cursor}; /// /// // Note that for `Cursor` the read and write halves share a single /// // seek position. This may or may not be true for other types that @@ -380,8 +375,7 @@ pub trait AsyncReadExt: AsyncRead { /// /// ``` /// # futures::executor::block_on(async { - /// use futures::io::AsyncReadExt; - /// use std::io::Cursor; + /// use futures::io::{AsyncReadExt, Cursor}; /// /// let reader = Cursor::new(&b"12345678"[..]); /// let mut buffer = [0; 5]; @@ -484,8 +478,7 @@ pub trait AsyncWriteExt: AsyncWrite { /// /// ``` /// # futures::executor::block_on(async { - /// use futures::io::AsyncWriteExt; - /// use std::io::Cursor; + /// use futures::io::{AsyncWriteExt, Cursor}; /// /// let mut writer = Cursor::new(vec![0u8; 5]); /// @@ -578,8 +571,7 @@ pub trait AsyncBufReadExt: AsyncBufRead { /// /// ``` /// # futures::executor::block_on(async { - /// use futures::io::{AsyncBufReadExt, AsyncWriteExt}; - /// use std::io::Cursor; + /// use futures::io::{AsyncBufReadExt, AsyncWriteExt, Cursor}; /// /// let reader = Cursor::new([1, 2, 3, 4]); /// let mut writer = Cursor::new(vec![0u8; 5]); @@ -617,8 +609,7 @@ pub trait AsyncBufReadExt: AsyncBufRead { /// /// ``` /// # futures::executor::block_on(async { - /// use futures::io::AsyncBufReadExt; - /// use std::io::Cursor; + /// use futures::io::{AsyncBufReadExt, Cursor}; /// /// let mut cursor = Cursor::new(b"lorem-ipsum"); /// let mut buf = vec![]; @@ -679,8 +670,7 @@ pub trait AsyncBufReadExt: AsyncBufRead { /// /// ``` /// # futures::executor::block_on(async { - /// use futures::io::AsyncBufReadExt; - /// use std::io::Cursor; + /// use futures::io::{AsyncBufReadExt, Cursor}; /// /// let mut cursor = Cursor::new(b"foo\nbar"); /// let mut buf = String::new(); @@ -729,9 +719,8 @@ pub trait AsyncBufReadExt: AsyncBufRead { /// /// ``` /// # futures::executor::block_on(async { - /// use futures::io::AsyncBufReadExt; + /// use futures::io::{AsyncBufReadExt, Cursor}; /// use futures::stream::StreamExt; - /// use std::io::Cursor; /// /// let cursor = Cursor::new(b"lorem\nipsum\r\ndolor"); /// diff --git a/futures-util/src/io/take.rs b/futures-util/src/io/take.rs index c667e75b99..b1f33fa468 100644 --- a/futures-util/src/io/take.rs +++ b/futures-util/src/io/take.rs @@ -37,8 +37,7 @@ impl Take { /// /// ``` /// # futures::executor::block_on(async { - /// use futures::io::AsyncReadExt; - /// use std::io::Cursor; + /// use futures::io::{AsyncReadExt, Cursor}; /// /// let reader = Cursor::new(&b"12345678"[..]); /// let mut buffer = [0; 2]; @@ -62,8 +61,7 @@ impl Take { /// /// ``` /// # futures::executor::block_on(async { - /// use futures::io::AsyncReadExt; - /// use std::io::Cursor; + /// use futures::io::{AsyncReadExt, Cursor}; /// /// let reader = Cursor::new(&b"12345678"[..]); /// let mut buffer = [0; 4]; @@ -90,8 +88,7 @@ impl Take { /// /// ``` /// # futures::executor::block_on(async { - /// use futures::io::AsyncReadExt; - /// use std::io::Cursor; + /// use futures::io::{AsyncReadExt, Cursor}; /// /// let reader = Cursor::new(&b"12345678"[..]); /// let mut buffer = [0; 4]; @@ -118,8 +115,7 @@ impl Take { /// /// ``` /// # futures::executor::block_on(async { - /// use futures::io::AsyncReadExt; - /// use std::io::Cursor; + /// use futures::io::{AsyncReadExt, Cursor}; /// /// let reader = Cursor::new(&b"12345678"[..]); /// let mut buffer = [0; 4]; @@ -150,8 +146,7 @@ impl Take { /// /// ``` /// # futures::executor::block_on(async { - /// use futures::io::AsyncReadExt; - /// use std::io::Cursor; + /// use futures::io::{AsyncReadExt, Cursor}; /// /// let reader = Cursor::new(&b"12345678"[..]); /// let mut buffer = [0; 4]; diff --git a/futures/src/lib.rs b/futures/src/lib.rs index 4df77be851..4055a7f0c7 100644 --- a/futures/src/lib.rs +++ b/futures/src/lib.rs @@ -287,10 +287,11 @@ pub mod io { pub use futures_util::io::{ AsyncReadExt, AsyncWriteExt, AsyncSeekExt, AsyncBufReadExt, AllowStdIo, - BufReader, BufWriter, Chain, Close, CopyInto, CopyBufInto, empty, Empty, - Flush, IntoSink, Lines, Read, ReadExact, ReadHalf, ReadLine, ReadToEnd, - ReadToString, ReadUntil, ReadVectored, repeat, Repeat, Seek, sink, Sink, - Take, Window, Write, WriteAll, WriteHalf, WriteVectored, + BufReader, BufWriter, Cursor, Chain, Close, CopyInto, CopyBufInto, + empty, Empty, Flush, IntoSink, Lines, Read, ReadExact, ReadHalf, + ReadLine, ReadToEnd, ReadToString, ReadUntil, ReadVectored, repeat, + Repeat, Seek, sink, Sink, Take, Window, Write, WriteAll, WriteHalf, + WriteVectored, }; } diff --git a/futures/tests/io_buf_reader.rs b/futures/tests/io_buf_reader.rs index 85184edbe7..69cb538714 100644 --- a/futures/tests/io_buf_reader.rs +++ b/futures/tests/io_buf_reader.rs @@ -2,12 +2,12 @@ use futures::executor::block_on; use futures::future::{Future, FutureExt}; use futures::io::{ AsyncSeek, AsyncSeekExt, AsyncBufRead, AsyncBufReadExt, AsyncRead, AsyncReadExt, - AllowStdIo, BufReader, SeekFrom, + AllowStdIo, BufReader, Cursor, SeekFrom, }; use futures::task::{Context, Poll}; use futures_test::task::noop_context; use std::cmp; -use std::io::{self, Cursor}; +use std::io; use std::pin::Pin; /// A dummy reader intended at testing short-reads propagation. diff --git a/futures/tests/io_buf_writer.rs b/futures/tests/io_buf_writer.rs index 4c3dcc1d3f..c7c194f64d 100644 --- a/futures/tests/io_buf_writer.rs +++ b/futures/tests/io_buf_writer.rs @@ -1,9 +1,9 @@ use futures::executor::block_on; use futures::future::{Future, FutureExt}; -use futures::io::{AsyncSeek, AsyncSeekExt, AsyncWrite, AsyncWriteExt, BufWriter, SeekFrom}; +use futures::io::{AsyncSeek, AsyncSeekExt, AsyncWrite, AsyncWriteExt, BufWriter, Cursor, SeekFrom}; use futures::task::{Context, Poll}; use futures_test::task::noop_context; -use std::io::{self, Cursor}; +use std::io; use std::pin::Pin; #[test] diff --git a/futures/tests/io_cursor.rs b/futures/tests/io_cursor.rs index ad48ed3446..4f80a75a37 100644 --- a/futures/tests/io_cursor.rs +++ b/futures/tests/io_cursor.rs @@ -1,8 +1,7 @@ use assert_matches::assert_matches; use futures::future::lazy; -use futures::io::AsyncWrite; +use futures::io::{AsyncWrite, Cursor}; use futures::task::Poll; -use std::io::Cursor; use std::pin::Pin; #[test] diff --git a/futures/tests/io_lines.rs b/futures/tests/io_lines.rs index d9b0622d7b..39eafa9a66 100644 --- a/futures/tests/io_lines.rs +++ b/futures/tests/io_lines.rs @@ -1,11 +1,10 @@ use futures::executor::block_on; use futures::future::{Future, FutureExt}; use futures::stream::{self, StreamExt, TryStreamExt}; -use futures::io::AsyncBufReadExt; +use futures::io::{AsyncBufReadExt, Cursor}; use futures::task::Poll; use futures_test::io::AsyncReadTestExt; use futures_test::task::noop_context; -use std::io::Cursor; macro_rules! block_on_next { ($expr:expr) => { diff --git a/futures/tests/io_read_line.rs b/futures/tests/io_read_line.rs index b1476444bc..d1dba5e6d2 100644 --- a/futures/tests/io_read_line.rs +++ b/futures/tests/io_read_line.rs @@ -1,11 +1,10 @@ use futures::executor::block_on; use futures::future::{Future, FutureExt}; use futures::stream::{self, StreamExt, TryStreamExt}; -use futures::io::AsyncBufReadExt; +use futures::io::{AsyncBufReadExt, Cursor}; use futures::task::Poll; use futures_test::io::AsyncReadTestExt; use futures_test::task::noop_context; -use std::io::Cursor; #[test] fn read_line() { diff --git a/futures/tests/io_read_to_string.rs b/futures/tests/io_read_to_string.rs index a31c5609e3..db825af21c 100644 --- a/futures/tests/io_read_to_string.rs +++ b/futures/tests/io_read_to_string.rs @@ -1,11 +1,10 @@ use futures::executor::block_on; use futures::future::{Future, FutureExt}; use futures::stream::{self, StreamExt, TryStreamExt}; -use futures::io::AsyncReadExt; +use futures::io::{AsyncReadExt, Cursor}; use futures::task::Poll; use futures_test::io::AsyncReadTestExt; use futures_test::task::noop_context; -use std::io::Cursor; #[test] fn read_to_string() { diff --git a/futures/tests/io_read_until.rs b/futures/tests/io_read_until.rs index 7bb05462eb..5152281795 100644 --- a/futures/tests/io_read_until.rs +++ b/futures/tests/io_read_until.rs @@ -1,11 +1,10 @@ use futures::executor::block_on; use futures::future::{Future, FutureExt}; use futures::stream::{self, StreamExt, TryStreamExt}; -use futures::io::AsyncBufReadExt; +use futures::io::{AsyncBufReadExt, Cursor}; use futures::task::Poll; use futures_test::io::AsyncReadTestExt; use futures_test::task::noop_context; -use std::io::Cursor; #[test] fn read_until() {