diff --git a/futures-io/Cargo.toml b/futures-io/Cargo.toml index ba8cd4aa7d..d99219e8e4 100644 --- a/futures-io/Cargo.toml +++ b/futures-io/Cargo.toml @@ -15,12 +15,13 @@ 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"] +nightly = [] +iovec = [] [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 d13aa960d8..69d3c0b1af 100644 --- a/futures-io/src/lib.rs +++ b/futures-io/src/lib.rs @@ -11,6 +11,10 @@ #![doc(html_root_url = "https://rust-lang-nursery.github.io/futures-api-docs/0.3.0-alpha.14/futures_io")] #![feature(futures_api)] +#![cfg_attr(feature = "iovec", feature(iovec))] + +#[cfg(all(feature = "iovec", not(feature = "nightly")))] +compile_error!("The `iovec` feature requires the `nightly` feature as an explicit opt-in to unstable features"); #[cfg(feature = "std")] mod if_std { @@ -21,8 +25,9 @@ mod if_std { use std::pin::Pin; use std::ptr; - // Re-export IoVec for convenience - pub use iovec::IoVec; + // Re-export IoVec and IoVecMut for convenience + #[cfg(feature = "iovec")] + pub use self::StdIo::{IoVec, IoVecMut}; // Re-export io::Error so that users don't have to deal // with conflicts when `use`ing `futures::io` and `std::io`. @@ -134,7 +139,8 @@ 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]) + #[cfg(feature = "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) { @@ -195,7 +201,8 @@ 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]) + #[cfg(feature = "iovec")] + fn poll_write_vectored(self: Pin<&mut Self>, cx: &mut Context<'_>, vec: &[IoVec<'_>]) -> Poll> { if let Some(ref first_iovec) = vec.get(0) { @@ -254,10 +261,11 @@ 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]) + #[cfg(feature = "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) } } } @@ -281,10 +289,11 @@ mod if_std { T::poll_read((*self).as_mut(), cx, buf) } - fn poll_vectored_read(mut self: Pin<&mut Self>, cx: &mut Context<'_>, vec: &mut [&mut IoVec]) + #[cfg(feature = "iovec")] + fn poll_read_vectored(mut self: Pin<&mut Self>, cx: &mut Context<'_>, vec: &mut [IoVecMut<'_>]) -> Poll> { - T::poll_vectored_read((*self).as_mut(), cx, vec) + T::poll_read_vectored((*self).as_mut(), cx, vec) } } @@ -301,6 +310,13 @@ mod if_std { { Poll::Ready(StdIo::Read::read(&mut *self, buf)) } + + #[cfg(feature = "iovec")] + fn poll_read_vectored(mut self: Pin<&mut Self>, _: &mut Context<'_>, vec: &mut [IoVecMut<'_>]) + -> Poll> + { + Poll::Ready(StdIo::Read::read_vectored(&mut *self, vec)) + } } } @@ -324,10 +340,11 @@ 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]) + #[cfg(feature = "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> { @@ -355,10 +372,11 @@ mod if_std { T::poll_write((*self).as_mut(), cx, buf) } - fn poll_vectored_write(mut self: Pin<&mut Self>, cx: &mut Context<'_>, vec: &[&IoVec]) + #[cfg(feature = "iovec")] + fn poll_write_vectored(mut self: Pin<&mut Self>, cx: &mut Context<'_>, vec: &[IoVec<'_>]) -> Poll> { - T::poll_vectored_write((*self).as_mut(), cx, vec) + T::poll_write_vectored((*self).as_mut(), cx, vec) } fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { @@ -378,6 +396,13 @@ mod if_std { Poll::Ready(StdIo::Write::write(&mut *self, buf)) } + #[cfg(feature = "iovec")] + 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)) } @@ -406,6 +431,13 @@ mod if_std { Poll::Ready(result) } + #[cfg(feature = "iovec")] + 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/Cargo.toml b/futures-util/Cargo.toml index 205d2732c4..73c76dd8a8 100644 --- a/futures-util/Cargo.toml +++ b/futures-util/Cargo.toml @@ -20,9 +20,10 @@ default = ["std", "futures-core-preview/either", "futures-sink-preview/either"] compat = ["std", "futures_01"] io-compat = ["compat", "tokio-io"] bench = [] -nightly = ["futures-core-preview/nightly", "futures-sink-preview/nightly"] +nightly = ["futures-core-preview/nightly", "futures-io-preview/nightly", "futures-sink-preview/nightly"] cfg-target-has-atomic = ["futures-core-preview/cfg-target-has-atomic"] alloc = ["futures-core-preview/alloc", "futures-sink-preview/alloc"] +iovec = ["futures-io-preview/iovec"] [dependencies] futures-core-preview = { path = "../futures-core", version = "=0.3.0-alpha.14", default-features = false } diff --git a/futures-util/src/io/mod.rs b/futures-util/src/io/mod.rs index 8c34a38283..69e23f19a2 100644 --- a/futures-util/src/io/mod.rs +++ b/futures-util/src/io/mod.rs @@ -7,7 +7,10 @@ use std::vec::Vec; -pub use futures_io::{AsyncRead, AsyncWrite, IoVec}; +pub use futures_io::{AsyncRead, AsyncWrite}; + +#[cfg(feature = "iovec")] +pub use futures_io::{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..c8f6b0e181 100644 --- a/futures-util/src/io/split.rs +++ b/futures-util/src/io/split.rs @@ -1,6 +1,8 @@ use crate::lock::BiLock; use futures_core::task::{Context, Poll}; -use futures_io::{AsyncRead, AsyncWrite, IoVec}; +use futures_io::{AsyncRead, AsyncWrite}; +#[cfg(feature = "iovec")] +use futures_io::{IoVec, IoVecMut}; use std::io; use std::pin::Pin; @@ -43,10 +45,11 @@ 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]) + #[cfg(feature = "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 +60,11 @@ 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]) + #[cfg(feature = "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-util/src/lib.rs b/futures-util/src/lib.rs index bf7acc9818..ca6f4d805e 100644 --- a/futures-util/src/lib.rs +++ b/futures-util/src/lib.rs @@ -5,6 +5,7 @@ #![cfg_attr(feature = "alloc", feature(box_into_pin))] #![cfg_attr(feature = "std", feature(async_await, await_macro))] #![cfg_attr(feature = "cfg-target-has-atomic", feature(cfg_target_has_atomic))] +#![cfg_attr(feature = "iovec", feature(iovec))] #![cfg_attr(not(feature = "std"), no_std)] #![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)] @@ -14,6 +15,9 @@ #[cfg(all(feature = "cfg-target-has-atomic", not(feature = "nightly")))] compile_error!("The `cfg-target-has-atomic` feature requires the `nightly` feature as an explicit opt-in to unstable features"); +#[cfg(all(feature = "iovec", not(feature = "nightly")))] +compile_error!("The `iovec` feature requires the `nightly` feature as an explicit opt-in to unstable features"); + #[cfg(feature = "alloc")] extern crate alloc; diff --git a/futures/Cargo.toml b/futures/Cargo.toml index 1f97687352..54aea78c87 100644 --- a/futures/Cargo.toml +++ b/futures/Cargo.toml @@ -36,10 +36,11 @@ futures-test-preview = { path = "../futures-test", version = "=0.3.0-alpha.14" } tokio = "0.1.11" [features] -nightly = ["futures-core-preview/nightly", "futures-sink-preview/nightly", "futures-util-preview/nightly"] +nightly = ["futures-core-preview/nightly", "futures-io-preview/nightly", "futures-sink-preview/nightly", "futures-util-preview/nightly"] std = ["alloc", "futures-core-preview/std", "futures-executor-preview/std", "futures-io-preview/std", "futures-sink-preview/std", "futures-util-preview/std"] default = ["std"] compat = ["std", "futures-util-preview/compat"] io-compat = ["compat", "futures-util-preview/io-compat"] cfg-target-has-atomic = ["futures-core-preview/cfg-target-has-atomic", "futures-util-preview/cfg-target-has-atomic"] alloc = ["futures-core-preview/alloc", "futures-sink-preview/alloc", "futures-util-preview/alloc"] +iovec = ["futures-io-preview/iovec", "futures-util-preview/iovec"] diff --git a/futures/src/lib.rs b/futures/src/lib.rs index 9e3060130c..a86cc68fbb 100644 --- a/futures/src/lib.rs +++ b/futures/src/lib.rs @@ -23,6 +23,7 @@ #![feature(futures_api)] #![cfg_attr(feature = "cfg-target-has-atomic", feature(cfg_target_has_atomic))] +#![cfg_attr(feature = "iovec", feature(iovec))] #![cfg_attr(not(feature = "std"), no_std)] @@ -33,6 +34,9 @@ #[cfg(all(feature = "cfg-target-has-atomic", not(feature = "nightly")))] compile_error!("The `cfg-target-has-atomic` feature requires the `nightly` feature as an explicit opt-in to unstable features"); +#[cfg(all(feature = "iovec", not(feature = "nightly")))] +compile_error!("The `iovec` feature requires the `nightly` feature as an explicit opt-in to unstable features"); + #[doc(hidden)] pub use futures_util::core_reexport; #[doc(hidden)] pub use futures_core::future::Future; @@ -255,8 +259,12 @@ pub mod io { //! sinks. pub use futures_io::{ - Error, Initializer, IoVec, ErrorKind, AsyncRead, AsyncWrite, Result + Error, Initializer, ErrorKind, AsyncRead, AsyncWrite, Result, }; + + #[cfg(feature = "iovec")] + pub use futures_io::{IoVec, IoVecMut}; + pub use futures_util::io::{ AsyncReadExt, AsyncWriteExt, AllowStdIo, Close, CopyInto, Flush, Read, ReadExact, ReadHalf, ReadToEnd, Window, WriteAll, WriteHalf,