diff --git a/futures-io/Cargo.toml b/futures-io/Cargo.toml index ba8cd4aa7d..d0b4603cdf 100644 --- a/futures-io/Cargo.toml +++ b/futures-io/Cargo.toml @@ -15,12 +15,11 @@ The `AsyncRead` and `AsyncWrite` traits for the futures-rs library. name = "futures_io" [features] -std = ["futures-core-preview/std", "iovec"] +std = ["futures-core-preview/std"] default = ["std"] [dependencies] futures-core-preview = { path = "../futures-core", version = "=0.3.0-alpha.14", default-features = false } -iovec = { version = "0.1", optional = true } [dev-dependencies] futures-preview = { path = "../futures", version = "=0.3.0-alpha.14" } diff --git a/futures-io/src/lib.rs b/futures-io/src/lib.rs index d9e04c88ca..2992602a7b 100644 --- a/futures-io/src/lib.rs +++ b/futures-io/src/lib.rs @@ -20,14 +20,12 @@ mod if_std { use std::pin::Pin; use std::ptr; - // Re-export IoVec for convenience - pub use iovec::IoVec; - - // Re-export io::Error so that users don't have to deal + // Re-export some `std::io` items so that users don't have to deal // with conflicts when `use`ing `futures::io` and `std::io`. pub use self::StdIo::Error as Error; pub use self::StdIo::ErrorKind as ErrorKind; pub use self::StdIo::Result as Result; + pub use self::StdIo::{IoVec as IoVec, IoVecMut as IoVecMut}; /// A type used to conditionally initialize buffers passed to `AsyncRead` /// methods, modeled after `std`. @@ -133,7 +131,7 @@ mod if_std { /// `Interrupted`. Implementations must convert `WouldBlock` into /// `Poll::Pending` and either internally retry or convert /// `Interrupted` into another error kind. - fn poll_vectored_read(self: Pin<&mut Self>, cx: &mut Context<'_>, vec: &mut [&mut IoVec]) + fn poll_read_vectored(self: Pin<&mut Self>, cx: &mut Context<'_>, vec: &mut [IoVecMut<'_>]) -> Poll> { if let Some(ref mut first_iovec) = vec.get_mut(0) { @@ -194,7 +192,7 @@ mod if_std { /// `Interrupted`. Implementations must convert `WouldBlock` into /// `Poll::Pending` and either internally retry or convert /// `Interrupted` into another error kind. - fn poll_vectored_write(self: Pin<&mut Self>, cx: &mut Context<'_>, vec: &[&IoVec]) + fn poll_write_vectored(self: Pin<&mut Self>, cx: &mut Context<'_>, vec: &[IoVec<'_>]) -> Poll> { if let Some(ref first_iovec) = vec.get(0) { @@ -253,10 +251,10 @@ mod if_std { Pin::new(&mut **self).poll_read(cx, buf) } - fn poll_vectored_read(mut self: Pin<&mut Self>, cx: &mut Context<'_>, vec: &mut [&mut IoVec]) + fn poll_read_vectored(mut self: Pin<&mut Self>, cx: &mut Context<'_>, vec: &mut [IoVecMut<'_>]) -> Poll> { - Pin::new(&mut **self).poll_vectored_read(cx, vec) + Pin::new(&mut **self).poll_read_vectored(cx, vec) } } } @@ -284,7 +282,7 @@ mod if_std { Pin::get_mut(self).as_mut().poll_read(cx, buf) } - fn poll_vectored_read(self: Pin<&mut Self>, cx: &mut Context<'_>, vec: &mut [&mut IoVec]) + fn poll_vectored_read(self: Pin<&mut Self>, cx: &mut Context<'_>, vec: &mut [IoVecMut<'_>]) -> Poll> { Pin::get_mut(self).as_mut().poll_vectored_read(cx, vec) @@ -304,6 +302,12 @@ mod if_std { { Poll::Ready(StdIo::Read::read(&mut *self, buf)) } + + fn poll_read_vectored(mut self: Pin<&mut Self>, _: &mut Context<'_>, vec: &mut [IoVecMut<'_>]) + -> Poll> + { + Poll::Ready(StdIo::Read::read_vectored(&mut *self, vec)) + } } } @@ -327,10 +331,10 @@ mod if_std { Pin::new(&mut **self).poll_write(cx, buf) } - fn poll_vectored_write(mut self: Pin<&mut Self>, cx: &mut Context<'_>, vec: &[&IoVec]) + fn poll_write_vectored(mut self: Pin<&mut Self>, cx: &mut Context<'_>, vec: &[IoVec<'_>]) -> Poll> { - Pin::new(&mut **self).poll_vectored_write(cx, vec) + Pin::new(&mut **self).poll_write_vectored(cx, vec) } fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { @@ -362,7 +366,7 @@ mod if_std { Pin::get_mut(self).as_mut().poll_write(cx, buf) } - fn poll_vectored_write(self: Pin<&mut Self>, cx: &mut Context<'_>, vec: &[&IoVec]) + fn poll_vectored_write(self: Pin<&mut Self>, cx: &mut Context<'_>, vec: &[IoVec<'_>]) -> Poll> { Pin::get_mut(self).as_mut().poll_vectored_write(cx, vec) @@ -385,6 +389,12 @@ mod if_std { Poll::Ready(StdIo::Write::write(&mut *self, buf)) } + fn poll_write_vectored(mut self: Pin<&mut Self>, _: &mut Context<'_>, vec: &[IoVec<'_>]) + -> Poll> + { + Poll::Ready(StdIo::Write::write_vectored(&mut *self, vec)) + } + fn poll_flush(mut self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll> { Poll::Ready(StdIo::Write::flush(&mut *self)) } @@ -413,6 +423,12 @@ mod if_std { Poll::Ready(result) } + fn poll_write_vectored(self: Pin<&mut Self>, _: &mut Context<'_>, vec: &[IoVec<'_>]) + -> Poll> + { + Poll::Ready(StdIo::Write::write_vectored(&mut self.get_mut().get_mut().as_mut(), vec)) + } + fn poll_flush(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll> { Poll::Ready(StdIo::Write::flush(&mut self.get_mut().get_mut().as_mut())) } diff --git a/futures-util/src/io/mod.rs b/futures-util/src/io/mod.rs index e2c2473472..7c56768f68 100644 --- a/futures-util/src/io/mod.rs +++ b/futures-util/src/io/mod.rs @@ -7,7 +7,7 @@ use std::vec::Vec; -pub use futures_io::{AsyncRead, AsyncWrite, IoVec}; +pub use futures_io::{AsyncRead, AsyncWrite, IoVec, IoVecMut}; #[cfg(feature = "io-compat")] use crate::compat::Compat; diff --git a/futures-util/src/io/split.rs b/futures-util/src/io/split.rs index 333fc17983..3fae5c509b 100644 --- a/futures-util/src/io/split.rs +++ b/futures-util/src/io/split.rs @@ -1,6 +1,6 @@ use crate::lock::BiLock; use futures_core::task::{Context, Poll}; -use futures_io::{AsyncRead, AsyncWrite, IoVec}; +use futures_io::{AsyncRead, AsyncWrite, IoVec, IoVecMut}; use std::io; use std::pin::Pin; @@ -43,10 +43,10 @@ impl AsyncRead for ReadHalf { lock_and_then(&self.handle, cx, |l, cx| l.poll_read(cx, buf)) } - fn poll_vectored_read(self: Pin<&mut Self>, cx: &mut Context<'_>, vec: &mut [&mut IoVec]) + fn poll_read_vectored(self: Pin<&mut Self>, cx: &mut Context<'_>, vec: &mut [IoVecMut<'_>]) -> Poll> { - lock_and_then(&self.handle, cx, |l, cx| l.poll_vectored_read(cx, vec)) + lock_and_then(&self.handle, cx, |l, cx| l.poll_read_vectored(cx, vec)) } } @@ -57,10 +57,10 @@ impl AsyncWrite for WriteHalf { lock_and_then(&self.handle, cx, |l, cx| l.poll_write(cx, buf)) } - fn poll_vectored_write(self: Pin<&mut Self>, cx: &mut Context<'_>, vec: &[&IoVec]) + fn poll_write_vectored(self: Pin<&mut Self>, cx: &mut Context<'_>, vec: &[IoVec<'_>]) -> Poll> { - lock_and_then(&self.handle, cx, |l, cx| l.poll_vectored_write(cx, vec)) + lock_and_then(&self.handle, cx, |l, cx| l.poll_write_vectored(cx, vec)) } fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { diff --git a/futures/src/lib.rs b/futures/src/lib.rs index f20f7a86a3..a83e9bd56e 100644 --- a/futures/src/lib.rs +++ b/futures/src/lib.rs @@ -268,8 +268,9 @@ pub mod io { //! sinks. pub use futures_io::{ - Error, Initializer, IoVec, ErrorKind, AsyncRead, AsyncWrite, Result + Error, Initializer, IoVec, IoVecMut, ErrorKind, AsyncRead, AsyncWrite, Result, }; + pub use futures_util::io::{ AsyncReadExt, AsyncWriteExt, AllowStdIo, Close, CopyInto, Flush, Read, ReadExact, ReadHalf, ReadToEnd, Window, WriteAll, WriteHalf,