Skip to content

Commit e576173

Browse files
committed
Add iovec feature
1 parent 0d2c6d9 commit e576173

File tree

8 files changed

+61
-8
lines changed

8 files changed

+61
-8
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.14", default-features = false }

futures-io/src/lib.rs

Lines changed: 32 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.14/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
/// `Poll::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>, cx: &mut Context<'_>, vec: &mut [IoVecMut<'_>])
139144
-> Poll<Result<usize>>
140145
{
@@ -196,6 +201,7 @@ mod if_std {
196201
/// `Interrupted`. Implementations must convert `WouldBlock` into
197202
/// `Poll::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>, cx: &mut Context<'_>, vec: &[IoVec<'_>])
200206
-> Poll<Result<usize>>
201207
{
@@ -255,6 +261,7 @@ mod if_std {
255261
Pin::new(&mut **self).poll_read(cx, buf)
256262
}
257263

264+
#[cfg(feature = "iovec")]
258265
fn poll_vectored_read(mut self: Pin<&mut Self>, cx: &mut Context<'_>, vec: &mut [IoVecMut<'_>])
259266
-> Poll<Result<usize>>
260267
{
@@ -282,6 +289,7 @@ mod if_std {
282289
T::poll_read((*self).as_mut(), cx, buf)
283290
}
284291

292+
#[cfg(feature = "iovec")]
285293
fn poll_vectored_read(mut self: Pin<&mut Self>, cx: &mut Context<'_>, vec: &mut [IoVecMut<'_>])
286294
-> Poll<Result<usize>>
287295
{
@@ -302,6 +310,13 @@ mod if_std {
302310
{
303311
Poll::Ready(StdIo::Read::read(&mut *self, buf))
304312
}
313+
314+
#[cfg(feature = "iovec")]
315+
fn poll_vectored_read(mut self: Pin<&mut Self>, _: &mut Context<'_>, vec: &mut [IoVecMut<'_>])
316+
-> Poll<Result<usize>>
317+
{
318+
Poll::Ready(StdIo::Read::read_vectored(&mut *self, vec))
319+
}
305320
}
306321
}
307322

@@ -325,6 +340,7 @@ mod if_std {
325340
Pin::new(&mut **self).poll_write(cx, buf)
326341
}
327342

343+
#[cfg(feature = "iovec")]
328344
fn poll_vectored_write(mut self: Pin<&mut Self>, cx: &mut Context<'_>, vec: &[IoVec<'_>])
329345
-> Poll<Result<usize>>
330346
{
@@ -356,6 +372,7 @@ mod if_std {
356372
T::poll_write((*self).as_mut(), cx, buf)
357373
}
358374

375+
#[cfg(feature = "iovec")]
359376
fn poll_vectored_write(mut self: Pin<&mut Self>, cx: &mut Context<'_>, vec: &[IoVec<'_>])
360377
-> Poll<Result<usize>>
361378
{
@@ -379,6 +396,13 @@ mod if_std {
379396
Poll::Ready(StdIo::Write::write(&mut *self, buf))
380397
}
381398

399+
#[cfg(feature = "iovec")]
400+
fn poll_vectored_write(mut self: Pin<&mut Self>, _: &mut Context<'_>, vec: &[IoVec<'_>])
401+
-> Poll<Result<usize>>
402+
{
403+
Poll::Ready(StdIo::Write::write_vectored(&mut *self, vec))
404+
}
405+
382406
fn poll_flush(mut self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Result<()>> {
383407
Poll::Ready(StdIo::Write::flush(&mut *self))
384408
}
@@ -407,6 +431,13 @@ mod if_std {
407431
Poll::Ready(result)
408432
}
409433

434+
#[cfg(feature = "iovec")]
435+
fn poll_vectored_write(self: Pin<&mut Self>, _: &mut Context<'_>, vec: &[IoVec<'_>])
436+
-> Poll<Result<usize>>
437+
{
438+
Poll::Ready(StdIo::Write::write_vectored(&mut self.get_mut().get_mut().as_mut(), vec))
439+
}
440+
410441
fn poll_flush(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Result<()>> {
411442
Poll::Ready(StdIo::Write::flush(&mut self.get_mut().get_mut().as_mut()))
412443
}

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 = ["futures-core-preview/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.14", 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::{Context, 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, cx, |l, cx| l.poll_read(cx, buf))
4446
}
4547

48+
#[cfg(feature = "iovec")]
4649
fn poll_vectored_read(self: Pin<&mut Self>, cx: &mut Context<'_>, 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, cx, |l, cx| l.poll_write(cx, buf))
5861
}
5962

63+
#[cfg(feature = "iovec")]
6064
fn poll_vectored_write(self: Pin<&mut Self>, cx: &mut Context<'_>, 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,8 +3,9 @@
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))]
8+
#![cfg_attr(feature = "iovec", feature(iovec))]
89

910
#![cfg_attr(not(feature = "std"), no_std)]
1011
#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)]
@@ -14,6 +15,9 @@
1415
#[cfg(all(feature = "cfg-target-has-atomic", not(feature = "nightly")))]
1516
compile_error!("The `cfg-target-has-atomic` feature requires the `nightly` feature as an explicit opt-in to unstable features");
1617

18+
#[cfg(all(feature = "iovec", not(feature = "nightly")))]
19+
compile_error!("The `iovec` feature requires the `nightly` feature as an explicit opt-in to unstable features");
20+
1721
#[cfg(feature = "alloc")]
1822
extern crate alloc;
1923

futures/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@ futures-test-preview = { path = "../futures-test", version = "=0.3.0-alpha.14" }
3636
tokio = "0.1.11"
3737

3838
[features]
39-
nightly = ["futures-core-preview/nightly", "futures-sink-preview/nightly", "futures-util-preview/nightly"]
39+
nightly = ["futures-core-preview/nightly", "futures-io-preview/nightly", "futures-sink-preview/nightly", "futures-util-preview/nightly"]
4040
std = ["alloc", "futures-core-preview/std", "futures-executor-preview/std", "futures-io-preview/std", "futures-sink-preview/std", "futures-util-preview/std"]
4141
default = ["std"]
4242
compat = ["std", "futures-util-preview/compat"]
4343
io-compat = ["compat", "futures-util-preview/io-compat"]
4444
cfg-target-has-atomic = ["futures-core-preview/cfg-target-has-atomic", "futures-util-preview/cfg-target-has-atomic"]
4545
alloc = ["futures-core-preview/alloc", "futures-sink-preview/alloc", "futures-util-preview/alloc"]
46+
iovec = ["futures-io-preview/iovec", "futures-util-preview/iovec"]

futures/src/lib.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
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))]
26+
#![cfg_attr(feature = "iovec", feature(iovec))]
2727

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

@@ -34,6 +34,9 @@
3434
#[cfg(all(feature = "cfg-target-has-atomic", not(feature = "nightly")))]
3535
compile_error!("The `cfg-target-has-atomic` feature requires the `nightly` feature as an explicit opt-in to unstable features");
3636

37+
#[cfg(all(feature = "iovec", not(feature = "nightly")))]
38+
compile_error!("The `iovec` feature requires the `nightly` feature as an explicit opt-in to unstable features");
39+
3740
#[doc(hidden)] pub use futures_util::core_reexport;
3841

3942
#[doc(hidden)] pub use futures_core::future::Future;
@@ -256,8 +259,12 @@ pub mod io {
256259
//! sinks.
257260
258261
pub use futures_io::{
259-
Error, Initializer, IoVec, IoVecMut, ErrorKind, AsyncRead, AsyncWrite, Result
262+
Error, Initializer, ErrorKind, AsyncRead, AsyncWrite, Result,
260263
};
264+
265+
#[cfg(feature = "iovec")]
266+
pub use futures_io::{IoVec, IoVecMut};
267+
261268
pub use futures_util::io::{
262269
AsyncReadExt, AsyncWriteExt, AllowStdIo, Close, CopyInto, Flush,
263270
Read, ReadExact, ReadHalf, ReadToEnd, Window, WriteAll, WriteHalf,

0 commit comments

Comments
 (0)