diff --git a/Cargo.toml b/Cargo.toml index 2114d1e1..22e1efbc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,9 +39,9 @@ members = [ ] [dependencies] +atomic-waker = "1.0.0" futures-core = { version = "0.3", default-features = false } futures-sink = { version = "0.3", default-features = false } -futures-util = { version = "0.3", default-features = false } tokio-util = { version = "0.7.1", features = ["codec", "io"] } tokio = { version = "1", features = ["io-util"] } bytes = "1" diff --git a/src/client.rs b/src/client.rs index 8449ff8c..6d2b9690 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1492,7 +1492,7 @@ impl ResponseFuture { impl PushPromises { /// Get the next `PushPromise`. pub async fn push_promise(&mut self) -> Option> { - futures_util::future::poll_fn(move |cx| self.poll_push_promise(cx)).await + crate::poll_fn(move |cx| self.poll_push_promise(cx)).await } #[doc(hidden)] diff --git a/src/lib.rs b/src/lib.rs index 5f596653..1120e106 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -139,3 +139,25 @@ pub use crate::share::{FlowControl, Ping, PingPong, Pong, RecvStream, SendStream #[cfg(feature = "unstable")] pub use codec::{Codec, SendError, UserError}; + +use std::future::Future; +use std::pin::Pin; +use std::task::{Context, Poll}; + +/// Creates a future from a function that returns `Poll`. +fn poll_fn) -> T>(f: F) -> PollFn { + PollFn(f) +} + +/// The future created by `poll_fn`. +struct PollFn(F); + +impl Unpin for PollFn {} + +impl) -> Poll> Future for PollFn { + type Output = T; + + fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { + (self.0)(cx) + } +} diff --git a/src/proto/ping_pong.rs b/src/proto/ping_pong.rs index 59023e26..692c0bae 100644 --- a/src/proto/ping_pong.rs +++ b/src/proto/ping_pong.rs @@ -2,8 +2,8 @@ use crate::codec::Codec; use crate::frame::Ping; use crate::proto::{self, PingPayload}; +use atomic_waker::AtomicWaker; use bytes::Buf; -use futures_util::task::AtomicWaker; use std::io; use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::Arc; diff --git a/src/server.rs b/src/server.rs index 4f872226..27f89d41 100644 --- a/src/server.rs +++ b/src/server.rs @@ -413,7 +413,7 @@ where pub async fn accept( &mut self, ) -> Option, SendResponse), crate::Error>> { - futures_util::future::poll_fn(move |cx| self.poll_accept(cx)).await + crate::poll_fn(move |cx| self.poll_accept(cx)).await } #[doc(hidden)] diff --git a/src/share.rs b/src/share.rs index 26b42879..fd305708 100644 --- a/src/share.rs +++ b/src/share.rs @@ -410,12 +410,12 @@ impl RecvStream { /// Get the next data frame. pub async fn data(&mut self) -> Option> { - futures_util::future::poll_fn(move |cx| self.poll_data(cx)).await + crate::poll_fn(move |cx| self.poll_data(cx)).await } /// Get optional trailers for this stream. pub async fn trailers(&mut self) -> Result, crate::Error> { - futures_util::future::poll_fn(move |cx| self.poll_trailers(cx)).await + crate::poll_fn(move |cx| self.poll_trailers(cx)).await } /// Poll for the next data frame. @@ -549,7 +549,7 @@ impl PingPong { /// Send a PING frame and wait for the peer to send the pong. pub async fn ping(&mut self, ping: Ping) -> Result { self.send_ping(ping)?; - futures_util::future::poll_fn(|cx| self.poll_pong(cx)).await + crate::poll_fn(|cx| self.poll_pong(cx)).await } #[doc(hidden)]