Skip to content

Commit

Permalink
Use our own io::Cursor
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Nov 4, 2019
1 parent 23401d3 commit 3020a05
Show file tree
Hide file tree
Showing 13 changed files with 283 additions and 102 deletions.
38 changes: 0 additions & 38 deletions futures-io/src/lib.rs
Expand Up @@ -385,10 +385,6 @@ mod if_std {
delegate_async_read_to_stdio!();
}

impl<T: AsRef<[u8]> + Unpin> AsyncRead for io::Cursor<T> {
delegate_async_read_to_stdio!();
}

macro_rules! deref_async_write {
() => {
fn poll_write(mut self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8])
Expand Down Expand Up @@ -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<u8>> {
delegate_async_write_to_stdio!();
}

impl AsyncWrite for io::Cursor<Vec<u8>> {
delegate_async_write_to_stdio!();
}

impl AsyncWrite for io::Cursor<Box<[u8]>> {
delegate_async_write_to_stdio!();
}

impl AsyncWrite for Vec<u8> {
delegate_async_write_to_stdio!();
}
Expand Down Expand Up @@ -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<Result<u64>>
{
Poll::Ready(io::Seek::seek(&mut *self, pos))
}
}
}

impl<T: AsRef<[u8]> + Unpin> AsyncSeek for io::Cursor<T> {
delegate_async_seek_to_stdio!();
}

macro_rules! deref_async_buf_read {
() => {
fn poll_fill_buf(self: Pin<&mut Self>, cx: &mut Context<'_>)
Expand Down Expand Up @@ -590,10 +556,6 @@ mod if_std {
impl AsyncBufRead for &[u8] {
delegate_async_buf_read_to_stdio!();
}

impl<T: AsRef<[u8]> + Unpin> AsyncBufRead for io::Cursor<T> {
delegate_async_buf_read_to_stdio!();
}
}

#[cfg(feature = "std")]
Expand Down
12 changes: 6 additions & 6 deletions futures-test/src/io/read/mod.rs
Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions futures-test/src/io/write/mod.rs
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions futures-util/src/compat/compat01as03.rs
Expand Up @@ -383,11 +383,11 @@ mod io {
/// #![feature(impl_trait_in_bindings)]
/// # #![allow(incomplete_features)]
/// # futures::executor::block_on(async {
/// use futures::io::AsyncReadExt;
/// use futures::io::{AsyncReadExt, Cursor};
/// use futures_util::compat::AsyncRead01CompatExt;
///
/// let input = b"Hello World!";
/// let reader: impl tokio_io::AsyncRead = std::io::Cursor::new(input);
/// let reader: impl tokio_io::AsyncRead = Cursor::new(input);
/// let mut reader: impl futures::io::AsyncRead + Unpin = reader.compat();
///
/// let mut output = Vec::with_capacity(12);
Expand All @@ -411,11 +411,11 @@ mod io {
///
/// ```
/// # futures::executor::block_on(async {
/// use futures::io::AsyncWriteExt;
/// use futures::io::{AsyncWriteExt, Cursor};
/// use futures_util::compat::AsyncWrite01CompatExt;
///
/// let input = b"Hello World!";
/// let mut cursor = std::io::Cursor::new(Vec::with_capacity(12));
/// let mut cursor = Cursor::new(Vec::with_capacity(12));
///
/// let mut writer = (&mut cursor).compat();
/// writer.write_all(input).await.unwrap();
Expand Down

0 comments on commit 3020a05

Please sign in to comment.