From 04b542885f0d47d0221aab90e9184beeccda04eb Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Sun, 25 Aug 2019 07:57:34 +0900 Subject: [PATCH] Expose BiLock as unstable feature --- .travis.yml | 7 ++++++- futures-util/Cargo.toml | 2 +- futures-util/benches_disabled/bilock.rs | 2 +- futures-util/src/lib.rs | 4 ++-- futures-util/src/lock/bilock.rs | 3 +++ futures-util/src/lock/mod.rs | 10 ++++++---- futures/Cargo.toml | 1 + futures/src/lib.rs | 15 +++++++++++++-- .../tests_disabled}/bilock.rs | 0 9 files changed, 33 insertions(+), 11 deletions(-) rename {futures-util => futures/tests_disabled}/bilock.rs (100%) diff --git a/.travis.yml b/.travis.yml index 7716513128..ecf7379a4e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -75,7 +75,7 @@ matrix: rust: nightly script: - cargo bench --all - - cargo bench --manifest-path futures-util/Cargo.toml --features=bench,unstable + - cargo bench --manifest-path futures-util/Cargo.toml --features=bilock,unstable - name: cargo +stable build --no-default-features rust: stable @@ -146,11 +146,16 @@ matrix: - cargo check --manifest-path futures-util/Cargo.toml --features io-compat - cargo check --manifest-path futures-util/Cargo.toml --features sink,compat - cargo check --manifest-path futures-util/Cargo.toml --features sink,channel + - cargo check --manifest-path futures-util/Cargo.toml --features sink,bilock,unstable + - cargo check --manifest-path futures-util/Cargo.toml --features io,bilock,unstable + - cargo check --manifest-path futures-util/Cargo.toml --features sink,io - cargo check --manifest-path futures-util/Cargo.toml --no-default-features - cargo check --manifest-path futures-util/Cargo.toml --no-default-features --features sink - cargo check --manifest-path futures-util/Cargo.toml --no-default-features --features alloc,sink - cargo check --manifest-path futures-util/Cargo.toml --no-default-features --features async-await + - cargo check --manifest-path futures-util/Cargo.toml --no-default-features --features sink,bilock,unstable + - cargo check --manifest-path futures-util/Cargo.toml --no-default-features --features io,bilock,unstable - name: cargo doc rust: nightly diff --git a/futures-util/Cargo.toml b/futures-util/Cargo.toml index 32654e073b..360dd3ec3f 100644 --- a/futures-util/Cargo.toml +++ b/futures-util/Cargo.toml @@ -32,7 +32,7 @@ select-macro = ["async-await", "futures-select-macro-preview", "proc-macro-hack" # `unstable` feature as an explicit opt-in to unstable API. unstable = ["futures-core-preview/unstable"] cfg-target-has-atomic = ["futures-core-preview/cfg-target-has-atomic"] -bench = [] +bilock = [] [dependencies] futures-core-preview = { path = "../futures-core", version = "=0.3.0-alpha.18", default-features = false } diff --git a/futures-util/benches_disabled/bilock.rs b/futures-util/benches_disabled/bilock.rs index 4b1a172ecc..78b5edb6bf 100644 --- a/futures-util/benches_disabled/bilock.rs +++ b/futures-util/benches_disabled/bilock.rs @@ -1,6 +1,6 @@ #![feature(test)] -#[cfg(feature = "bench")] +#[cfg(feature = "bilock")] mod bench { use futures::task::{Context, Waker}; use futures::executor::LocalPool; diff --git a/futures-util/src/lib.rs b/futures-util/src/lib.rs index db95c297ea..ef216e650e 100644 --- a/futures-util/src/lib.rs +++ b/futures-util/src/lib.rs @@ -16,8 +16,8 @@ #[cfg(all(feature = "cfg-target-has-atomic", not(feature = "unstable")))] compile_error!("The `cfg-target-has-atomic` feature requires the `unstable` feature as an explicit opt-in to unstable features"); -#[cfg(all(feature = "bench", not(feature = "unstable")))] -compile_error!("The `bench` feature requires the `unstable` feature as an explicit opt-in to unstable features"); +#[cfg(all(feature = "bilock", not(feature = "unstable")))] +compile_error!("The `bilock` feature requires the `unstable` feature as an explicit opt-in to unstable features"); #[cfg(feature = "alloc")] extern crate alloc; diff --git a/futures-util/src/lock/bilock.rs b/futures-util/src/lock/bilock.rs index f749dc2af6..57664b8559 100644 --- a/futures-util/src/lock/bilock.rs +++ b/futures-util/src/lock/bilock.rs @@ -35,6 +35,9 @@ use std::error::Error; /// example a TCP stream could be both a reader and a writer or a framing layer /// could be both a stream and a sink for messages. A `BiLock` enables splitting /// these two and then using each independently in a futures-powered fashion. +/// +/// This type is only available when the `bilock` feature of this +/// library is activated. #[derive(Debug)] pub struct BiLock { arc: Arc>, diff --git a/futures-util/src/lock/mod.rs b/futures-util/src/lock/mod.rs index 7a5dc11461..bc52ca4905 100644 --- a/futures-util/src/lock/mod.rs +++ b/futures-util/src/lock/mod.rs @@ -1,16 +1,18 @@ //! Futures-powered synchronization primitives. +//! +//! This module is only available when the `std` or `alloc` feature of this +//! library is activated, and it is activated by default. #[cfg(feature = "std")] mod mutex; #[cfg(feature = "std")] pub use self::mutex::{Mutex, MutexLockFuture, MutexGuard}; -#[cfg(any(feature = "sink", feature = "io"))] +#[cfg(any(feature = "bilock", feature = "sink", feature = "io"))] #[allow(unreachable_pub)] mod bilock; -#[cfg(any(feature = "sink", feature = "io"))] -#[cfg(any(test, feature = "bench"))] +#[cfg(feature = "bilock")] pub use self::bilock::{BiLock, BiLockAcquire, BiLockGuard, ReuniteError}; #[cfg(any(feature = "sink", feature = "io"))] -#[cfg(not(any(test, feature = "bench")))] +#[cfg(not(feature = "bilock"))] pub(crate) use self::bilock::BiLock; diff --git a/futures/Cargo.toml b/futures/Cargo.toml index 56d6355bc6..e17f4833d1 100644 --- a/futures/Cargo.toml +++ b/futures/Cargo.toml @@ -48,6 +48,7 @@ io-compat = ["compat", "futures-util-preview/io-compat"] # `unstable` feature as an explicit opt-in to unstable API. unstable = ["futures-core-preview/unstable", "futures-channel-preview/unstable", "futures-util-preview/unstable"] cfg-target-has-atomic = ["futures-core-preview/cfg-target-has-atomic", "futures-channel-preview/cfg-target-has-atomic", "futures-util-preview/cfg-target-has-atomic"] +bilock = ["futures-util-preview/bilock"] [package.metadata.docs.rs] all-features = true diff --git a/futures/src/lib.rs b/futures/src/lib.rs index df60e1b60e..08c63ece53 100644 --- a/futures/src/lib.rs +++ b/futures/src/lib.rs @@ -37,6 +37,9 @@ #[cfg(all(feature = "cfg-target-has-atomic", not(feature = "unstable")))] compile_error!("The `cfg-target-has-atomic` feature requires the `unstable` feature as an explicit opt-in to unstable features"); +#[cfg(all(feature = "bilock", not(feature = "unstable")))] +compile_error!("The `bilock` feature requires the `unstable` feature as an explicit opt-in to unstable features"); + #[doc(hidden)] pub use futures_core::core_reexport; #[doc(hidden)] pub use futures_core::future::Future; @@ -307,13 +310,21 @@ pub mod io { }; } -#[cfg(feature = "std")] +#[cfg_attr( + feature = "cfg-target-has-atomic", + cfg(all(target_has_atomic = "cas", target_has_atomic = "ptr")) +)] +#[cfg(feature = "alloc")] pub mod lock { //! Futures-powered synchronization primitives. //! - //! This module is only available when the `std` feature of this + //! This module is only available when the `std` or `alloc` feature of this //! library is activated, and it is activated by default. + #[cfg(feature = "bilock")] + pub use futures_util::lock::{BiLock, BiLockAcquire, BiLockGuard, ReuniteError}; + + #[cfg(feature = "std")] pub use futures_util::lock::{Mutex, MutexLockFuture, MutexGuard}; } diff --git a/futures-util/bilock.rs b/futures/tests_disabled/bilock.rs similarity index 100% rename from futures-util/bilock.rs rename to futures/tests_disabled/bilock.rs