From 52c72426c1c377504addda2ffaccea6557f776ff Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Wed, 3 Jun 2020 18:38:20 +0200 Subject: [PATCH 1/3] fix: do not require the runtime to use unstable features --- Cargo.toml | 9 ++++++--- src/future/mod.rs | 8 ++++---- src/task/mod.rs | 2 ++ src/utils.rs | 44 +++++++++++++++++++++++--------------------- 4 files changed, 35 insertions(+), 28 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d02577e..bf08bee 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,9 +29,13 @@ default = [ "log", "num_cpus", "pin-project-lite", + "smol", ] docs = ["attributes", "unstable", "default"] -unstable = ["std"] +unstable = [ + "std", + "futures-timer", +] attributes = ["async-attributes"] std = [ "alloc", @@ -42,8 +46,6 @@ std = [ "once_cell", "pin-utils", "slab", - "smol", - "futures-timer", "wasm-bindgen-futures", "futures-channel", ] @@ -66,6 +68,7 @@ once_cell = { version = "1.3.1", optional = true } pin-project-lite = { version = "0.1.4", optional = true } pin-utils = { version = "0.1.0-alpha.4", optional = true } slab = { version = "0.4.2", optional = true } +futures-timer = { version = "3.0.2", optional = true } # Devdepencency, but they are not allowed to be optional :/ surf = { version = "1.0.3", optional = true } diff --git a/src/future/mod.rs b/src/future/mod.rs index 9b75533..db0607a 100644 --- a/src/future/mod.rs +++ b/src/future/mod.rs @@ -61,10 +61,10 @@ cfg_std! { mod ready; } -cfg_default! { - pub use timeout::{timeout, TimeoutError}; - mod timeout; -} +#[cfg(any(feature = "unstable", feature = "default"))] +pub use timeout::{timeout, TimeoutError}; +#[cfg(any(feature = "unstable", feature = "default"))] +mod timeout; cfg_unstable! { pub use into_future::IntoFuture; diff --git a/src/task/mod.rs b/src/task/mod.rs index eefc7c2..ca0b92a 100644 --- a/src/task/mod.rs +++ b/src/task/mod.rs @@ -168,7 +168,9 @@ cfg_default! { } cfg_unstable! { + #[cfg(feature = "default")] pub use spawn_local::spawn_local; + #[cfg(feature = "default")] mod spawn_local; } diff --git a/src/utils.rs b/src/utils.rs index 7c9aa99..e7ea9ec 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -60,36 +60,38 @@ pub(crate) trait Context { } #[cfg(all(not(target_os = "unknown"), feature = "default"))] -pub(crate) type Timer = smol::Timer; +mod timer { + pub type Timer = smol::Timer; +} -#[cfg(all(target_arch = "wasm32", feature = "default"))] -#[derive(Debug)] -pub(crate) struct Timer(futures_timer::Delay); +#[cfg(any(all(target_arch = "wasm32", feature = "default"), feature = "unstable"))] +mod timer { + use std::pin::Pin; + use std::task::Poll; -#[cfg(all(target_arch = "wasm32", feature = "default"))] -impl Timer { - pub(crate) fn after(dur: std::time::Duration) -> Self { - Timer(futures_timer::Delay::new(dur)) - } -} + #[derive(Debug)] + pub(crate) struct Timer(futures_timer::Delay); -#[cfg(target_arch = "wasm32")] -use std::pin::Pin; -#[cfg(target_arch = "wasm32")] -use std::task::Poll; + impl Timer { + pub(crate) fn after(dur: std::time::Duration) -> Self { + Timer(futures_timer::Delay::new(dur)) + } + } -#[cfg(target_arch = "wasm32")] -impl std::future::Future for Timer { - type Output = (); + impl std::future::Future for Timer { + type Output = (); - fn poll(mut self: Pin<&mut Self>, cx: &mut std::task::Context<'_>) -> Poll { - match Pin::new(&mut self.0).poll(cx) { - Poll::Pending => Poll::Pending, - Poll::Ready(_) => Poll::Ready(()), + fn poll(mut self: Pin<&mut Self>, cx: &mut std::task::Context<'_>) -> Poll { + match Pin::new(&mut self.0).poll(cx) { + Poll::Pending => Poll::Pending, + Poll::Ready(_) => Poll::Ready(()), + } } } } +pub(crate) use timer::*; + /// Defers evaluation of a block of code until the end of the scope. #[cfg(feature = "default")] #[doc(hidden)] From 8943ba82dd0e4cb8a29f6750a519a53080093944 Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Wed, 3 Jun 2020 18:43:19 +0200 Subject: [PATCH 2/3] fix nostd --- src/utils.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils.rs b/src/utils.rs index e7ea9ec..9ad4338 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -90,6 +90,7 @@ mod timer { } } +#[cfg(any(feature = "unstable", feature = "default"))] pub(crate) use timer::*; /// Defers evaluation of a block of code until the end of the scope. From 8389041414a4c39f3e899415d51d3cffdb121eea Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Wed, 3 Jun 2020 18:50:12 +0200 Subject: [PATCH 3/3] fix --- src/utils.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/utils.rs b/src/utils.rs index 9ad4338..e064570 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -64,7 +64,10 @@ mod timer { pub type Timer = smol::Timer; } -#[cfg(any(all(target_arch = "wasm32", feature = "default"), feature = "unstable"))] +#[cfg(any( + all(target_arch = "wasm32", feature = "default"), + all(feature = "unstable", not(feature = "default")) +))] mod timer { use std::pin::Pin; use std::task::Poll;