From 488c90c0c4cd2bb831b72ef520e69d1bad189dc3 Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Wed, 18 Sep 2019 01:26:04 +0200 Subject: [PATCH 01/10] add feature guards for unstable features Signed-off-by: Yoshua Wuyts --- src/future/timeout.rs | 2 ++ src/lib.rs | 11 +++++++++-- src/stream/double_ended_stream.rs | 1 + src/stream/from_stream.rs | 1 + src/stream/into_stream.rs | 1 + src/stream/mod.rs | 20 ++++++++++++++------ src/stream/stream/mod.rs | 9 ++++++++- 7 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/future/timeout.rs b/src/future/timeout.rs index e433bf183..bf7a6ff38 100644 --- a/src/future/timeout.rs +++ b/src/future/timeout.rs @@ -29,6 +29,7 @@ use crate::task::{Context, Poll}; /// # Ok(()) }) } /// ``` #[cfg_attr(feature = "docs", doc(cfg(unstable)))] +#[cfg(feature = "unstable")] pub async fn timeout(dur: Duration, f: F) -> Result where F: Future, @@ -69,6 +70,7 @@ impl Future for TimeoutFuture { /// An error returned when a future times out. #[cfg_attr(feature = "docs", doc(cfg(unstable)))] +#[cfg(feature = "unstable")] #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub struct TimeoutError { _private: (), diff --git a/src/lib.rs b/src/lib.rs index dfa9a07ac..83647bbc9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -42,17 +42,24 @@ #![doc(test(attr(allow(unused_extern_crates, unused_variables))))] #![doc(html_logo_url = "https://async.rs/images/logo--hero.svg")] +use cfg_if::cfg_if; + pub mod fs; pub mod future; pub mod io; pub mod net; pub mod os; pub mod prelude; -mod result; pub mod stream; pub mod sync; pub mod task; -mod vec; + +cfg_if! { + if #[cfg(any(feature = "unstable", feature = "docs"))] { + mod vec; + mod result; + } +} #[cfg_attr(feature = "docs", doc(cfg(unstable)))] #[cfg(feature = "unstable")] diff --git a/src/stream/double_ended_stream.rs b/src/stream/double_ended_stream.rs index 2287cc649..bb5df74fb 100644 --- a/src/stream/double_ended_stream.rs +++ b/src/stream/double_ended_stream.rs @@ -11,6 +11,7 @@ use std::task::{Context, Poll}; /// /// [`Stream`]: trait.Stream.html #[cfg_attr(feature = "docs", doc(cfg(unstable)))] +#[cfg(feature = "unstable")] pub trait DoubleEndedStream: Stream { /// Removes and returns an element from the end of the stream. /// diff --git a/src/stream/from_stream.rs b/src/stream/from_stream.rs index 91d3e24bd..58b2ad175 100644 --- a/src/stream/from_stream.rs +++ b/src/stream/from_stream.rs @@ -11,6 +11,7 @@ use std::pin::Pin; /// /// [`IntoStream`]: trait.IntoStream.html #[cfg_attr(feature = "docs", doc(cfg(unstable)))] +#[cfg(feature = "unstable")] pub trait FromStream { /// Creates a value from a stream. /// diff --git a/src/stream/into_stream.rs b/src/stream/into_stream.rs index b2913170a..0a986a8ab 100644 --- a/src/stream/into_stream.rs +++ b/src/stream/into_stream.rs @@ -14,6 +14,7 @@ use futures_core::stream::Stream; /// /// [`FromStream`]: trait.FromStream.html #[cfg_attr(feature = "docs", doc(cfg(unstable)))] +#[cfg(feature = "unstable")] pub trait IntoStream { /// The type of the elements being iterated over. type Item; diff --git a/src/stream/mod.rs b/src/stream/mod.rs index ec1c23bc8..36cf3a4ef 100644 --- a/src/stream/mod.rs +++ b/src/stream/mod.rs @@ -21,18 +21,26 @@ //! # }) } //! ``` -pub use double_ended_stream::DoubleEndedStream; +use cfg_if::cfg_if; + pub use empty::{empty, Empty}; -pub use from_stream::FromStream; -pub use into_stream::IntoStream; pub use once::{once, Once}; pub use repeat::{repeat, Repeat}; pub use stream::{Fuse, Scan, Stream, Take, Zip}; -mod double_ended_stream; mod empty; -mod from_stream; -mod into_stream; mod once; mod repeat; mod stream; + +cfg_if! { + if #[cfg(any(feature = "unstable", feature = "docs"))] { + mod double_ended_stream; + mod from_stream; + mod into_stream; + + pub use double_ended_stream::DoubleEndedStream; + pub use from_stream::FromStream; + pub use into_stream::IntoStream; + } +} diff --git a/src/stream/stream/mod.rs b/src/stream/stream/mod.rs index 62f1b4b50..3a02a5c81 100644 --- a/src/stream/stream/mod.rs +++ b/src/stream/stream/mod.rs @@ -52,7 +52,6 @@ use min_by::MinByFuture; use next::NextFuture; use nth::NthFuture; -use super::from_stream::FromStream; use std::cmp::Ordering; use std::marker::PhantomData; use std::pin::Pin; @@ -60,6 +59,12 @@ use std::task::{Context, Poll}; use cfg_if::cfg_if; +cfg_if! { + if #[cfg(any(feature = "unstable", feature = "docs"))] { + use crate::stream::FromStream; + } +} + cfg_if! { if #[cfg(feature = "docs")] { #[doc(hidden)] @@ -748,6 +753,8 @@ pub trait Stream { /// /// [`stream`]: trait.Stream.html#tymethod.next #[must_use = "if you really need to exhaust the iterator, consider `.for_each(drop)` instead (TODO)"] + #[cfg_attr(feature = "docs", doc(cfg(unstable)))] + #[cfg(feature = "unstable")] fn collect<'a, B>(self) -> dyn_ret!('a, B) where Self: futures_core::stream::Stream + Sized + Send + 'a, From 713ab026c33694a5ca561afe996d47dda77eb132 Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Wed, 18 Sep 2019 03:47:47 +0200 Subject: [PATCH 02/10] build unstable for docs Signed-off-by: Yoshua Wuyts --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 19b3e5891..3eec1d559 100644 --- a/.travis.yml +++ b/.travis.yml @@ -50,7 +50,7 @@ matrix: rust: nightly os: linux script: - - cargo doc --features docs + - cargo doc --features docs unstable - name: book rust: nightly From b670600555087d013be35a872d1b019bdb5b029c Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Wed, 18 Sep 2019 12:42:46 +0200 Subject: [PATCH 03/10] Update src/stream/into_stream.rs Co-Authored-By: Stjepan Glavina --- src/stream/into_stream.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stream/into_stream.rs b/src/stream/into_stream.rs index 0a986a8ab..5e4311e68 100644 --- a/src/stream/into_stream.rs +++ b/src/stream/into_stream.rs @@ -14,7 +14,7 @@ use futures_core::stream::Stream; /// /// [`FromStream`]: trait.FromStream.html #[cfg_attr(feature = "docs", doc(cfg(unstable)))] -#[cfg(feature = "unstable")] +#[cfg(any(feature = "unstable", feature = "docs"))] pub trait IntoStream { /// The type of the elements being iterated over. type Item; From bfb16790c389d4246a3a01ef5c881a32eb861411 Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Wed, 18 Sep 2019 12:42:58 +0200 Subject: [PATCH 04/10] Update src/stream/from_stream.rs Co-Authored-By: Stjepan Glavina --- src/stream/from_stream.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stream/from_stream.rs b/src/stream/from_stream.rs index 58b2ad175..d046e3b1c 100644 --- a/src/stream/from_stream.rs +++ b/src/stream/from_stream.rs @@ -11,7 +11,7 @@ use std::pin::Pin; /// /// [`IntoStream`]: trait.IntoStream.html #[cfg_attr(feature = "docs", doc(cfg(unstable)))] -#[cfg(feature = "unstable")] +#[cfg(any(feature = "unstable", feature = "docs"))] pub trait FromStream { /// Creates a value from a stream. /// From f7ec3f4e2dbb15e3aea188906aa7e939e41679b7 Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Wed, 18 Sep 2019 12:43:06 +0200 Subject: [PATCH 05/10] Update src/stream/stream/mod.rs Co-Authored-By: Stjepan Glavina --- src/stream/stream/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stream/stream/mod.rs b/src/stream/stream/mod.rs index 3a02a5c81..6de9a31be 100644 --- a/src/stream/stream/mod.rs +++ b/src/stream/stream/mod.rs @@ -754,7 +754,7 @@ pub trait Stream { /// [`stream`]: trait.Stream.html#tymethod.next #[must_use = "if you really need to exhaust the iterator, consider `.for_each(drop)` instead (TODO)"] #[cfg_attr(feature = "docs", doc(cfg(unstable)))] - #[cfg(feature = "unstable")] + #[cfg(any(feature = "unstable", feature = "docs"))] fn collect<'a, B>(self) -> dyn_ret!('a, B) where Self: futures_core::stream::Stream + Sized + Send + 'a, From 9a07196402893605c0594b0c705dffa7f57091c7 Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Wed, 18 Sep 2019 12:43:14 +0200 Subject: [PATCH 06/10] Update src/stream/double_ended_stream.rs Co-Authored-By: Stjepan Glavina --- src/stream/double_ended_stream.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stream/double_ended_stream.rs b/src/stream/double_ended_stream.rs index bb5df74fb..6fab77c22 100644 --- a/src/stream/double_ended_stream.rs +++ b/src/stream/double_ended_stream.rs @@ -11,7 +11,7 @@ use std::task::{Context, Poll}; /// /// [`Stream`]: trait.Stream.html #[cfg_attr(feature = "docs", doc(cfg(unstable)))] -#[cfg(feature = "unstable")] +#[cfg(any(feature = "unstable", feature = "docs"))] pub trait DoubleEndedStream: Stream { /// Removes and returns an element from the end of the stream. /// From 6b76fb13087432fcee4209092bae113537b457ce Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Wed, 18 Sep 2019 12:43:27 +0200 Subject: [PATCH 07/10] Update src/future/timeout.rs Co-Authored-By: Stjepan Glavina --- src/future/timeout.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/future/timeout.rs b/src/future/timeout.rs index bf7a6ff38..566d27a0e 100644 --- a/src/future/timeout.rs +++ b/src/future/timeout.rs @@ -70,7 +70,7 @@ impl Future for TimeoutFuture { /// An error returned when a future times out. #[cfg_attr(feature = "docs", doc(cfg(unstable)))] -#[cfg(feature = "unstable")] +#[cfg(any(feature = "unstable", feature = "docs"))] #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub struct TimeoutError { _private: (), From 2964e72b00bacda6687fd7f491226a135a220cbc Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Wed, 18 Sep 2019 12:43:34 +0200 Subject: [PATCH 08/10] Update src/future/timeout.rs Co-Authored-By: Stjepan Glavina --- src/future/timeout.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/future/timeout.rs b/src/future/timeout.rs index 566d27a0e..aa88f6461 100644 --- a/src/future/timeout.rs +++ b/src/future/timeout.rs @@ -29,7 +29,7 @@ use crate::task::{Context, Poll}; /// # Ok(()) }) } /// ``` #[cfg_attr(feature = "docs", doc(cfg(unstable)))] -#[cfg(feature = "unstable")] +#[cfg(any(feature = "unstable", feature = "docs"))] pub async fn timeout(dur: Duration, f: F) -> Result where F: Future, From c533d5f90694fb6cdfdb3544396e5393e56fbd66 Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Wed, 18 Sep 2019 21:25:58 +0200 Subject: [PATCH 09/10] implement feedback & fix tests Signed-off-by: Yoshua Wuyts --- .travis.yml | 2 +- src/lib.rs | 5 +---- src/stream/stream/mod.rs | 1 + 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3eec1d559..3a2651b51 100644 --- a/.travis.yml +++ b/.travis.yml @@ -64,4 +64,4 @@ matrix: script: - cargo check --features unstable --all --benches --bins --examples --tests - - cargo test --features unstable --all + - cargo test --all --docs --features unstable diff --git a/src/lib.rs b/src/lib.rs index 83647bbc9..09d04b2a2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -56,13 +56,10 @@ pub mod task; cfg_if! { if #[cfg(any(feature = "unstable", feature = "docs"))] { + pub mod pin; mod vec; mod result; } } -#[cfg_attr(feature = "docs", doc(cfg(unstable)))] -#[cfg(feature = "unstable")] -pub mod pin; - pub(crate) mod utils; diff --git a/src/stream/stream/mod.rs b/src/stream/stream/mod.rs index 6de9a31be..8ddab2126 100644 --- a/src/stream/stream/mod.rs +++ b/src/stream/stream/mod.rs @@ -96,6 +96,7 @@ cfg_if! { ($a:lifetime, $o:ty) => (DynFuture<$a, $o>); } } else { + #[allow(unused_macros)] macro_rules! dyn_ret { ($a:lifetime, $o:ty) => (Pin + Send + 'a>>) } From bd43490d728bdb877b33044126c56ec4dbf6f061 Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Wed, 18 Sep 2019 22:56:13 +0200 Subject: [PATCH 10/10] fix cargo test --doc Signed-off-by: Yoshua Wuyts --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 3a2651b51..d2862fcae 100644 --- a/.travis.yml +++ b/.travis.yml @@ -64,4 +64,4 @@ matrix: script: - cargo check --features unstable --all --benches --bins --examples --tests - - cargo test --all --docs --features unstable + - cargo test --all --doc --features unstable