Skip to content

Commit fc18962

Browse files
taiki-ecramertj
authored andcommitted
Make more of futures-util dependencies optional
1 parent e55c9cd commit fc18962

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+175
-28
lines changed

.travis.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,28 @@ matrix:
119119
--no-default-features
120120
--features nightly,alloc
121121

122+
- name: cargo check (futures-util)
123+
rust: nightly
124+
script:
125+
- cargo run --manifest-path ci/remove-dev-dependencies/Cargo.toml */Cargo.toml
126+
127+
- cargo check --manifest-path futures-util/Cargo.toml
128+
- cargo check --manifest-path futures-util/Cargo.toml --all-features
129+
130+
- cargo check --manifest-path futures-util/Cargo.toml --features sink
131+
- cargo check --manifest-path futures-util/Cargo.toml --features io
132+
- cargo check --manifest-path futures-util/Cargo.toml --features channel
133+
- cargo check --manifest-path futures-util/Cargo.toml --features nightly,async-await
134+
- cargo check --manifest-path futures-util/Cargo.toml --features nightly,select-macro
135+
- cargo check --manifest-path futures-util/Cargo.toml --features compat
136+
- cargo check --manifest-path futures-util/Cargo.toml --features io-compat
137+
- cargo check --manifest-path futures-util/Cargo.toml --features sink,compat
138+
- cargo check --manifest-path futures-util/Cargo.toml --features sink,channel
139+
140+
- cargo check --manifest-path futures-util/Cargo.toml --no-default-features
141+
- cargo check --manifest-path futures-util/Cargo.toml --no-default-features --features sink
142+
- cargo check --manifest-path futures-util/Cargo.toml --no-default-features --features alloc,sink
143+
122144
- name: cargo doc
123145
rust: nightly
124146
script:

futures-sink/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ The asynchronous `Sink` trait for the futures-rs library.
1515
name = "futures_sink"
1616

1717
[features]
18-
std = ["alloc", "futures-core-preview/std"]
1918
default = ["std"]
20-
nightly = ["futures-core-preview/nightly"]
19+
std = ["alloc", "futures-core-preview/std"]
2120
alloc = ["futures-core-preview/alloc"]
2221

2322
[dependencies]

futures-test/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ futures-preview = { version = "=0.3.0-alpha.16", path = "../futures", default-fe
2626

2727
[features]
2828
default = ["std"]
29-
std = ["futures-core-preview/std", "futures-io-preview/std", "futures-util-preview/std", "futures-executor-preview/std"]
29+
std = ["futures-core-preview/std", "futures-io-preview/std", "futures-util-preview/std", "futures-util-preview/io", "futures-executor-preview/std"]

futures-util/Cargo.toml

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,25 @@ Common utilities and extension traits for the futures-rs library.
1515
name = "futures_util"
1616

1717
[features]
18-
std = ["alloc", "futures-core-preview/std", "futures-io-preview/std", "futures-sink-preview/std", "slab", "memchr"]
1918
default = ["std"]
20-
async-await = ["std", "futures-select-macro-preview", "proc-macro-hack", "proc-macro-nested", "rand"]
19+
std = ["alloc", "futures-core-preview/std", "slab"]
20+
alloc = ["futures-core-preview/alloc"]
21+
async-await = ["std"]
2122
compat = ["std", "futures_01"]
22-
io-compat = ["compat", "tokio-io"]
23+
io-compat = ["io", "compat", "tokio-io"]
2324
bench = []
24-
nightly = ["futures-core-preview/nightly", "futures-sink-preview/nightly"]
25+
nightly = ["futures-core-preview/nightly"]
2526
cfg-target-has-atomic = ["futures-core-preview/cfg-target-has-atomic"]
26-
alloc = ["futures-core-preview/alloc", "futures-sink-preview/alloc"]
27+
sink = ["futures-sink-preview"]
28+
io = ["std", "futures-io-preview", "memchr"]
29+
channel = ["std", "futures-channel-preview"]
30+
select-macro = ["async-await", "futures-select-macro-preview", "proc-macro-hack", "proc-macro-nested", "rand"]
2731

2832
[dependencies]
2933
futures-core-preview = { path = "../futures-core", version = "=0.3.0-alpha.16", default-features = false }
30-
futures-channel-preview = { path = "../futures-channel", version = "=0.3.0-alpha.16", default-features = false }
31-
futures-io-preview = { path = "../futures-io", version = "=0.3.0-alpha.16", default-features = false }
32-
futures-sink-preview = { path = "../futures-sink", version = "=0.3.0-alpha.16", default-features = false}
34+
futures-channel-preview = { path = "../futures-channel", version = "=0.3.0-alpha.16", default-features = false, features = ["std"], optional = true }
35+
futures-io-preview = { path = "../futures-io", version = "=0.3.0-alpha.16", default-features = false, features = ["std"], optional = true }
36+
futures-sink-preview = { path = "../futures-sink", version = "=0.3.0-alpha.16", default-features = false, optional = true }
3337
futures-select-macro-preview = { path = "../futures-select-macro", version = "=0.3.0-alpha.16", default-features = false, optional = true }
3438
proc-macro-hack = { version = "0.5", optional = true }
3539
proc-macro-nested = { version = "0.1.2", optional = true }
@@ -42,7 +46,6 @@ pin-utils = "0.1.0-alpha.4"
4246

4347
[dev-dependencies]
4448
futures-preview = { path = "../futures", version = "=0.3.0-alpha.16", features = ["async-await", "nightly"] }
45-
futures-executor-preview = { path = "../futures-executor", version = "=0.3.0-alpha.16" }
4649
futures-test-preview = { path = "../futures-test", version = "=0.3.0-alpha.16" }
4750
tokio = "0.1.11"
4851

futures-util/src/async_await/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ pub use self::pending::*;
2424
mod join;
2525

2626
// Primary export is a macro
27+
#[cfg(feature = "select-macro")]
2728
mod select_mod;
29+
#[cfg(feature = "select-macro")]
2830
pub use self::select_mod::*;
2931

3032
#[doc(hidden)]

futures-util/src/compat/compat01as03.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ use futures_01::executor::{
33
Spawn as Spawn01, UnsafeNotify as UnsafeNotify01,
44
};
55
use futures_01::{
6-
Async as Async01, AsyncSink as AsyncSink01, Future as Future01,
7-
Sink as Sink01, Stream as Stream01,
6+
Async as Async01, Future as Future01,
7+
Stream as Stream01,
88
};
9+
#[cfg(feature = "sink")]
10+
use futures_01::{AsyncSink as AsyncSink01, Sink as Sink01};
911
use futures_core::{task as task03, Future as Future03, Stream as Stream03};
1012
use std::pin::Pin;
1113
use std::task::Context;
14+
#[cfg(feature = "sink")]
1215
use futures_sink::Sink as Sink03;
1316

1417
#[cfg(feature = "io-compat")]
@@ -101,6 +104,7 @@ pub trait Stream01CompatExt: Stream01 {
101104
impl<St: Stream01> Stream01CompatExt for St {}
102105

103106
/// Extension trait for futures 0.1 [`Sink`](futures_01::sink::Sink)
107+
#[cfg(feature = "sink")]
104108
pub trait Sink01CompatExt: Sink01 {
105109
/// Converts a futures 0.1
106110
/// [`Sink<SinkItem = T, SinkError = E>`](futures_01::sink::Sink)
@@ -129,6 +133,7 @@ pub trait Sink01CompatExt: Sink01 {
129133
Compat01As03Sink::new(self)
130134
}
131135
}
136+
#[cfg(feature = "sink")]
132137
impl<Si: Sink01> Sink01CompatExt for Si {}
133138

134139
fn poll_01_to_03<T, E>(x: Result<Async01<T>, E>) -> task03::Poll<Result<T, E>> {
@@ -165,6 +170,7 @@ impl<St: Stream01> Stream03 for Compat01As03<St> {
165170
}
166171

167172
/// Converts a futures 0.1 Sink object to a futures 0.3-compatible version
173+
#[cfg(feature = "sink")]
168174
#[derive(Debug)]
169175
#[must_use = "sinks do nothing unless polled"]
170176
pub struct Compat01As03Sink<S, SinkItem> {
@@ -173,8 +179,10 @@ pub struct Compat01As03Sink<S, SinkItem> {
173179
pub(crate) close_started: bool,
174180
}
175181

182+
#[cfg(feature = "sink")]
176183
impl<S, SinkItem> Unpin for Compat01As03Sink<S, SinkItem> {}
177184

185+
#[cfg(feature = "sink")]
178186
impl<S, SinkItem> Compat01As03Sink<S, SinkItem> {
179187
/// Wraps a futures 0.1 Sink object in a futures 0.3-compatible wrapper.
180188
pub fn new(inner: S) -> Compat01As03Sink<S, SinkItem> {
@@ -200,6 +208,7 @@ impl<S, SinkItem> Compat01As03Sink<S, SinkItem> {
200208
}
201209
}
202210

211+
#[cfg(feature = "sink")]
203212
impl<S, SinkItem> Stream03 for Compat01As03Sink<S, SinkItem>
204213
where
205214
S: Stream01,
@@ -218,6 +227,7 @@ where
218227
}
219228
}
220229

230+
#[cfg(feature = "sink")]
221231
impl<S, SinkItem> Sink03<SinkItem> for Compat01As03Sink<S, SinkItem>
222232
where
223233
S: Sink01<SinkItem = SinkItem>,

futures-util/src/compat/compat03as01.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
use futures_01::{
2-
task as task01, Async as Async01, AsyncSink as AsyncSink01,
3-
Future as Future01, Poll as Poll01, Sink as Sink01,
4-
StartSend as StartSend01, Stream as Stream01,
2+
task as task01, Async as Async01, Future as Future01, Poll as Poll01,
3+
Stream as Stream01,
4+
};
5+
#[cfg(feature = "sink")]
6+
use futures_01::{
7+
AsyncSink as AsyncSink01, Sink as Sink01, StartSend as StartSend01,
58
};
69
use futures_core::{
710
task::{
@@ -12,10 +15,12 @@ use futures_core::{
1215
TryFuture as TryFuture03,
1316
TryStream as TryStream03,
1417
};
18+
#[cfg(feature = "sink")]
1519
use futures_sink::Sink as Sink03;
1620
use crate::task::{ArcWake as ArcWake03, WakerRef};
21+
#[cfg(feature = "sink")]
22+
use std::marker::PhantomData;
1723
use std::{
18-
marker::PhantomData,
1924
mem,
2025
pin::Pin,
2126
sync::Arc,
@@ -35,6 +40,7 @@ pub struct Compat<T> {
3540
}
3641

3742
/// Converts a futures 0.3 Sink object to a futures 0.1-compatible version
43+
#[cfg(feature = "sink")]
3844
#[derive(Debug)]
3945
#[must_use = "sinks do nothing unless polled"]
4046
pub struct CompatSink<T, Item> {
@@ -64,6 +70,7 @@ impl<T> Compat<T> {
6470
}
6571
}
6672

73+
#[cfg(feature = "sink")]
6774
impl<T, Item> CompatSink<T, Item> {
6875
/// Returns the inner item.
6976
pub fn into_inner(self) -> T {
@@ -116,6 +123,7 @@ where
116123
}
117124
}
118125

126+
#[cfg(feature = "sink")]
119127
impl<T, Item> Sink01 for CompatSink<T, Item>
120128
where
121129
T: Sink03<Item> + Unpin,
@@ -201,6 +209,7 @@ where
201209
f(Pin::new(&mut compat.inner), &mut cx)
202210
}
203211

212+
#[cfg(feature = "sink")]
204213
fn with_sink_context<T, Item, R, F>(compat: &mut CompatSink<T, Item>, f: F) -> R
205214
where
206215
T: Unpin,

futures-util/src/compat/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@ mod executor;
77
pub use self::executor::{Executor01CompatExt, Executor01Future, Executor01As03};
88

99
mod compat01as03;
10-
pub use self::compat01as03::{Compat01As03, Compat01As03Sink, Future01CompatExt, Stream01CompatExt, Sink01CompatExt};
11-
10+
pub use self::compat01as03::{Compat01As03, Future01CompatExt, Stream01CompatExt};
11+
#[cfg(feature = "sink")]
12+
pub use self::compat01as03::{Compat01As03Sink, Sink01CompatExt};
1213
#[cfg(feature = "io-compat")]
1314
pub use self::compat01as03::{AsyncRead01CompatExt, AsyncWrite01CompatExt};
1415

1516
mod compat03as01;
16-
pub use self::compat03as01::{Compat, CompatSink};
17+
pub use self::compat03as01::Compat;
18+
#[cfg(feature = "sink")]
19+
pub use self::compat03as01::CompatSink;

futures-util/src/future/either.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use core::pin::Pin;
22
use core::task::{Context, Poll};
33
use futures_core::future::{FusedFuture, Future};
44
use futures_core::stream::{FusedStream, Stream};
5+
#[cfg(feature = "sink")]
56
use futures_sink::Sink;
67

78
/// Combines two different futures, streams, or sinks having the same associated types into a single
@@ -108,6 +109,7 @@ where
108109
}
109110
}
110111

112+
#[cfg(feature = "sink")]
111113
impl<A, B, Item> Sink<Item> for Either<A, B>
112114
where
113115
A: Sink<Item>,
@@ -152,6 +154,7 @@ where
152154
}
153155
}
154156

157+
#[cfg(feature = "io")]
155158
#[cfg(feature = "std")]
156159
mod if_std {
157160
use super::Either;

futures-util/src/future/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,10 @@ mod catch_unwind;
9898
#[cfg(feature = "std")]
9999
pub use self::catch_unwind::CatchUnwind;
100100

101+
#[cfg(feature = "channel")]
101102
#[cfg(feature = "std")]
102103
mod remote_handle;
104+
#[cfg(feature = "channel")]
103105
#[cfg(feature = "std")]
104106
pub use self::remote_handle::{Remote, RemoteHandle};
105107

@@ -480,6 +482,7 @@ pub trait FutureExt: Future {
480482
///
481483
/// This method is only available when the `std` feature of this
482484
/// library is activated, and it is activated by default.
485+
#[cfg(feature = "channel")]
483486
#[cfg(feature = "std")]
484487
fn remote_handle(self) -> (Remote<Self>, RemoteHandle<Self::Output>)
485488
where

0 commit comments

Comments
 (0)