Skip to content

Commit 934ec27

Browse files
committed
Add iovec feature
1 parent 5de3a7d commit 934ec27

File tree

7 files changed

+58
-7
lines changed

7 files changed

+58
-7
lines changed

futures-io/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ name = "futures_io"
1717
[features]
1818
std = ["futures-core-preview/std"]
1919
default = ["std"]
20+
nightly = []
21+
iovec = []
2022

2123
[dependencies]
2224
futures-core-preview = { path = "../futures-core", version = "=0.3.0-alpha.13", default-features = false }

futures-io/src/lib.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
#![doc(html_root_url = "https://rust-lang-nursery.github.io/futures-api-docs/0.3.0-alpha.13/futures_io")]
1212

1313
#![feature(futures_api)]
14-
#![cfg_attr(feature = "std", feature(iovec))]
14+
#![cfg_attr(feature = "iovec", feature(iovec))]
15+
16+
#[cfg(all(feature = "iovec", not(feature = "nightly")))]
17+
compile_error!("The `iovec` feature requires the `nightly` feature as an explicit opt-in to unstable features");
1518

1619
#[cfg(feature = "std")]
1720
mod if_std {
@@ -23,6 +26,7 @@ mod if_std {
2326
use std::ptr;
2427

2528
// Re-export IoVec and IoVecMut for convenience
29+
#[cfg(feature = "iovec")]
2630
pub use self::StdIo::{IoVec, IoVecMut};
2731

2832
// Re-export io::Error so that users don't have to deal
@@ -135,6 +139,7 @@ mod if_std {
135139
/// `Interrupted`. Implementations must convert `WouldBlock` into
136140
/// `Async::Pending` and either internally retry or convert
137141
/// `Interrupted` into another error kind.
142+
#[cfg(feature = "iovec")]
138143
fn poll_vectored_read(self: Pin<&mut Self>, waker: &Waker, vec: &mut [IoVecMut<'_>])
139144
-> Poll<Result<usize>>
140145
{
@@ -196,6 +201,7 @@ mod if_std {
196201
/// `Interrupted`. Implementations must convert `WouldBlock` into
197202
/// `Async::Pending` and either internally retry or convert
198203
/// `Interrupted` into another error kind.
204+
#[cfg(feature = "iovec")]
199205
fn poll_vectored_write(self: Pin<&mut Self>, waker: &Waker, vec: &[IoVec<'_>])
200206
-> Poll<Result<usize>>
201207
{
@@ -255,6 +261,7 @@ mod if_std {
255261
Pin::new(&mut **self).poll_read(waker, buf)
256262
}
257263

264+
#[cfg(feature = "iovec")]
258265
fn poll_vectored_read(mut self: Pin<&mut Self>, waker: &Waker, vec: &mut [IoVecMut<'_>])
259266
-> Poll<Result<usize>>
260267
{
@@ -284,6 +291,13 @@ mod if_std {
284291
{
285292
Poll::Ready(StdIo::Read::read(&mut *self, buf))
286293
}
294+
295+
#[cfg(feature = "iovec")]
296+
fn poll_vectored_read(mut self: Pin<&mut Self>, _: &Waker, vec: &mut [IoVecMut<'_>])
297+
-> Poll<Result<usize>>
298+
{
299+
Poll::Ready(StdIo::Read::read_vectored(&mut *self, vec))
300+
}
287301
}
288302
}
289303

@@ -307,6 +321,7 @@ mod if_std {
307321
Pin::new(&mut **self).poll_write(waker, buf)
308322
}
309323

324+
#[cfg(feature = "iovec")]
310325
fn poll_vectored_write(mut self: Pin<&mut Self>, waker: &Waker, vec: &[IoVec<'_>])
311326
-> Poll<Result<usize>>
312327
{
@@ -338,6 +353,7 @@ mod if_std {
338353
T::poll_write((*self).as_mut(), waker, buf)
339354
}
340355

356+
#[cfg(feature = "iovec")]
341357
fn poll_vectored_write(mut self: Pin<&mut Self>, waker: &Waker, vec: &[IoVec<'_>])
342358
-> Poll<Result<usize>>
343359
{
@@ -361,6 +377,13 @@ mod if_std {
361377
Poll::Ready(StdIo::Write::write(&mut *self, buf))
362378
}
363379

380+
#[cfg(feature = "iovec")]
381+
fn poll_vectored_write(mut self: Pin<&mut Self>, _: &Waker, vec: &[IoVec<'_>])
382+
-> Poll<Result<usize>>
383+
{
384+
Poll::Ready(StdIo::Write::write_vectored(&mut *self, vec))
385+
}
386+
364387
fn poll_flush(mut self: Pin<&mut Self>, _: &Waker) -> Poll<Result<()>> {
365388
Poll::Ready(StdIo::Write::flush(&mut *self))
366389
}
@@ -389,6 +412,13 @@ mod if_std {
389412
Poll::Ready(result)
390413
}
391414

415+
#[cfg(feature = "iovec")]
416+
fn poll_vectored_write(self: Pin<&mut Self>, _: &Waker, vec: &[IoVec<'_>])
417+
-> Poll<Result<usize>>
418+
{
419+
Poll::Ready(StdIo::Write::write_vectored(&mut self.get_mut().get_mut().as_mut(), vec))
420+
}
421+
392422
fn poll_flush(self: Pin<&mut Self>, _: &Waker) -> Poll<Result<()>> {
393423
Poll::Ready(StdIo::Write::flush(&mut self.get_mut().get_mut().as_mut()))
394424
}

futures-util/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ default = ["std", "futures-core-preview/either", "futures-sink-preview/either"]
2020
compat = ["std", "futures_01"]
2121
io-compat = ["compat", "tokio-io"]
2222
bench = []
23-
nightly = ["futures-core-preview/nightly", "futures-sink-preview/nightly"]
23+
nightly = ["futures-core-preview/nightly", "futures-io-preview/nightly", "futures-sink-preview/nightly"]
2424
cfg-target-has-atomic = []
2525
alloc = ["futures-core-preview/alloc", "futures-sink-preview/alloc"]
26+
iovec = ["futures-io-preview/iovec"]
2627

2728
[dependencies]
2829
futures-core-preview = { path = "../futures-core", version = "=0.3.0-alpha.13", default-features = false }

futures-util/src/io/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
88
use std::vec::Vec;
99

10-
pub use futures_io::{AsyncRead, AsyncWrite, IoVec, IoVecMut};
10+
pub use futures_io::{AsyncRead, AsyncWrite};
11+
12+
#[cfg(feature = "iovec")]
13+
pub use futures_io::{IoVec, IoVecMut};
1114

1215
#[cfg(feature = "io-compat")] use crate::compat::Compat;
1316

futures-util/src/io/split.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use crate::lock::BiLock;
22
use futures_core::task::{Waker, Poll};
3-
use futures_io::{AsyncRead, AsyncWrite, IoVec, IoVecMut};
3+
use futures_io::{AsyncRead, AsyncWrite};
4+
#[cfg(feature = "iovec")]
5+
use futures_io::{IoVec, IoVecMut};
46
use std::io;
57
use std::pin::Pin;
68

@@ -43,6 +45,7 @@ impl<R: AsyncRead> AsyncRead for ReadHalf<R> {
4345
lock_and_then(&self.handle, waker, |l, waker| l.poll_read(waker, buf))
4446
}
4547

48+
#[cfg(feature = "iovec")]
4649
fn poll_vectored_read(self: Pin<&mut Self>, waker: &Waker, vec: &mut [IoVecMut<'_>])
4750
-> Poll<io::Result<usize>>
4851
{
@@ -57,6 +60,7 @@ impl<W: AsyncWrite> AsyncWrite for WriteHalf<W> {
5760
lock_and_then(&self.handle, waker, |l, waker| l.poll_write(waker, buf))
5861
}
5962

63+
#[cfg(feature = "iovec")]
6064
fn poll_vectored_write(self: Pin<&mut Self>, waker: &Waker, vec: &[IoVec<'_>])
6165
-> Poll<io::Result<usize>>
6266
{

futures-util/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
44
#![feature(futures_api)]
55
#![cfg_attr(feature = "alloc", feature(box_into_pin))]
6-
#![cfg_attr(feature = "std", feature(async_await, await_macro, iovec))]
6+
#![cfg_attr(feature = "std", feature(async_await, await_macro))]
77
#![cfg_attr(feature = "cfg-target-has-atomic", feature(cfg_target_has_atomic))]
88
#![cfg_attr(all(feature = "alloc", not(feature = "std")), feature(alloc, alloc_prelude))]
9+
#![cfg_attr(feature = "iovec", feature(iovec))]
910

1011
#![cfg_attr(not(feature = "std"), no_std)]
1112
#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)]
@@ -18,6 +19,9 @@ compile_error!("The `cfg-target-has-atomic` feature requires the `nightly` featu
1819
#[cfg(all(feature = "alloc", not(any(feature = "std", feature = "nightly"))))]
1920
compile_error!("The `alloc` feature without `std` requires the `nightly` feature active to explicitly opt-in to unstable features");
2021

22+
#[cfg(all(feature = "iovec", not(feature = "nightly")))]
23+
compile_error!("The `iovec` feature requires the `nightly` feature as an explicit opt-in to unstable features");
24+
2125
#[cfg(all(feature = "alloc", not(feature = "std")))]
2226
extern crate alloc;
2327
#[cfg(feature = "std")]

futures/src/lib.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
//! completion, but *do not block* the thread running them.
2323
2424
#![feature(futures_api)]
25-
#![cfg_attr(feature = "std", feature(iovec))]
2625
#![cfg_attr(feature = "cfg-target-has-atomic", feature(cfg_target_has_atomic))]
2726
#![cfg_attr(all(feature = "alloc", not(feature = "std")), feature(alloc))]
27+
#![cfg_attr(feature = "iovec", feature(iovec))]
2828

2929
#![cfg_attr(not(feature = "std"), no_std)]
3030

@@ -38,6 +38,9 @@ compile_error!("The `cfg-target-has-atomic` feature requires the `nightly` featu
3838
#[cfg(all(feature = "alloc", not(any(feature = "std", feature = "nightly"))))]
3939
compile_error!("The `alloc` feature without `std` requires the `nightly` feature active to explicitly opt-in to unstable features");
4040

41+
#[cfg(all(feature = "iovec", not(feature = "nightly")))]
42+
compile_error!("The `iovec` feature requires the `nightly` feature as an explicit opt-in to unstable features");
43+
4144
#[doc(hidden)] pub use futures_util::core_reexport;
4245

4346
#[doc(hidden)] pub use futures_core::future::Future;
@@ -257,8 +260,12 @@ pub mod io {
257260
//! sinks.
258261
259262
pub use futures_io::{
260-
Error, Initializer, IoVec, IoVecMut, ErrorKind, AsyncRead, AsyncWrite, Result
263+
Error, Initializer, ErrorKind, AsyncRead, AsyncWrite, Result,
261264
};
265+
266+
#[cfg(feature = "iovec")]
267+
pub use futures_io::{IoVec, IoVecMut};
268+
262269
pub use futures_util::io::{
263270
AsyncReadExt, AsyncWriteExt, AllowStdIo, Close, CopyInto, Flush,
264271
Read, ReadExact, ReadHalf, ReadToEnd, Window, WriteAll, WriteHalf,

0 commit comments

Comments
 (0)