Skip to content

refactor: reduce dependency on futures-util #3845

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/body/incoming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ use std::fmt;
#[cfg(all(feature = "http1", any(feature = "client", feature = "server")))]
use std::future::Future;
use std::pin::Pin;
#[cfg(all(
any(feature = "http1", feature = "http2"),
any(feature = "client", feature = "server")
))]
use std::task::ready;
use std::task::{Context, Poll};

use bytes::Bytes;
#[cfg(all(feature = "http1", any(feature = "client", feature = "server")))]
use futures_channel::{mpsc, oneshot};
#[cfg(all(
any(feature = "http1", feature = "http2"),
any(feature = "client", feature = "server")
))]
use futures_util::ready;
#[cfg(all(feature = "http1", any(feature = "client", feature = "server")))]
use futures_util::{stream::FusedStream, Stream}; // for mpsc::Receiver
#[cfg(all(feature = "http1", any(feature = "client", feature = "server")))]
Expand Down Expand Up @@ -368,7 +368,7 @@ impl Sender {

#[cfg(test)]
async fn ready(&mut self) -> crate::Result<()> {
futures_util::future::poll_fn(|cx| self.poll_ready(cx)).await
std::future::poll_fn(|cx| self.poll_ready(cx)).await
}

/// Send data on data channel when it is ready.
Expand Down
7 changes: 3 additions & 4 deletions src/client/conn/http1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ use std::error::Error as StdError;
use std::fmt;
use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll};
use std::task::{ready, Context, Poll};

use crate::rt::{Read, Write};
use bytes::Bytes;
use futures_util::ready;
use http::{Request, Response};
use httparse::ParserConfig;

Expand Down Expand Up @@ -92,7 +91,7 @@ where
/// instead run `into_parts`. This is a convenience wrapper over `poll_without_shutdown`.
pub async fn without_shutdown(self) -> crate::Result<Parts<T>> {
let mut conn = Some(self);
futures_util::future::poll_fn(move |cx| -> Poll<crate::Result<Parts<T>>> {
std::future::poll_fn(move |cx| -> Poll<crate::Result<Parts<T>>> {
ready!(conn.as_mut().unwrap().poll_without_shutdown(cx))?;
Poll::Ready(Ok(conn.take().unwrap().into_parts()))
})
Expand Down Expand Up @@ -148,7 +147,7 @@ impl<B> SendRequest<B> {
///
/// If the associated connection is closed, this returns an Error.
pub async fn ready(&mut self) -> crate::Result<()> {
futures_util::future::poll_fn(|cx| self.poll_ready(cx)).await
std::future::poll_fn(|cx| self.poll_ready(cx)).await
}

/// Checks if the connection is currently ready to send a request.
Expand Down
5 changes: 2 additions & 3 deletions src/client/conn/http2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ use std::future::Future;
use std::marker::PhantomData;
use std::pin::Pin;
use std::sync::Arc;
use std::task::{Context, Poll};
use std::task::{ready, Context, Poll};
use std::time::Duration;

use crate::rt::{Read, Write};
use futures_util::ready;
use http::{Request, Response};

use super::super::dispatch::{self, TrySendError};
Expand Down Expand Up @@ -99,7 +98,7 @@ impl<B> SendRequest<B> {
///
/// If the associated connection is closed, this returns an Error.
pub async fn ready(&mut self) -> crate::Result<()> {
futures_util::future::poll_fn(|cx| self.poll_ready(cx)).await
std::future::poll_fn(|cx| self.poll_ready(cx)).await
}

/// Checks if the connection is currently ready to send a request.
Expand Down
5 changes: 2 additions & 3 deletions src/proto/h1/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ use std::future::Future;
use std::io;
use std::marker::{PhantomData, Unpin};
use std::pin::Pin;
use std::task::{Context, Poll};
use std::task::{ready, Context, Poll};
#[cfg(feature = "server")]
use std::time::{Duration, Instant};

use crate::rt::{Read, Write};
use bytes::{Buf, Bytes};
use futures_util::ready;
use http::header::{HeaderValue, CONNECTION, TE};
use http::{HeaderMap, Method, Version};
use http_body::Frame;
Expand Down Expand Up @@ -1174,7 +1173,7 @@ mod tests {
.unwrap();

b.iter(|| {
rt.block_on(futures_util::future::poll_fn(|cx| {
rt.block_on(std::future::poll_fn(|cx| {
match conn.poll_read_head(cx) {
Poll::Ready(Some(Ok(x))) => {
::test::black_box(&x);
Expand Down
9 changes: 4 additions & 5 deletions src/proto/h1/decode.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use std::error::Error as StdError;
use std::fmt;
use std::io;
use std::task::{Context, Poll};
use std::task::{ready, Context, Poll};

use bytes::{BufMut, Bytes, BytesMut};
use futures_util::ready;
use http::{HeaderMap, HeaderName, HeaderValue};
use http_body::Frame;

Expand Down Expand Up @@ -244,7 +243,7 @@ impl Decoder {

#[cfg(test)]
async fn decode_fut<R: MemRead>(&mut self, body: &mut R) -> Result<Frame<Bytes>, io::Error> {
futures_util::future::poll_fn(move |cx| self.decode(cx, body)).await
std::future::poll_fn(move |cx| self.decode(cx, body)).await
}
}

Expand Down Expand Up @@ -746,7 +745,7 @@ mod tests {
let mut ext_cnt = 0;
let mut trailers_cnt = 0;
loop {
let result = futures_util::future::poll_fn(|cx| {
let result = std::future::poll_fn(|cx| {
state.step(
cx,
rdr,
Expand Down Expand Up @@ -776,7 +775,7 @@ mod tests {
let mut ext_cnt = 0;
let mut trailers_cnt = 0;
loop {
let result = futures_util::future::poll_fn(|cx| {
let result = std::future::poll_fn(|cx| {
state.step(
cx,
rdr,
Expand Down
3 changes: 1 addition & 2 deletions src/proto/h1/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ use std::{
future::Future,
marker::Unpin,
pin::Pin,
task::{Context, Poll},
task::{ready, Context, Poll},
};

use crate::rt::{Read, Write};
use bytes::{Buf, Bytes};
use futures_util::ready;
use http::Request;

use super::{Http1Transaction, Wants};
Expand Down
9 changes: 4 additions & 5 deletions src/proto/h1/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ use std::cmp;
use std::fmt;
use std::io::{self, IoSlice};
use std::pin::Pin;
use std::task::{Context, Poll};
use std::task::{ready, Context, Poll};

use crate::rt::{Read, ReadBuf, Write};
use bytes::{Buf, BufMut, Bytes, BytesMut};
use futures_util::ready;

use super::{Http1Transaction, ParseContext, ParsedMessage};
use crate::common::buf::BufList;
Expand Down Expand Up @@ -325,7 +324,7 @@ where

#[cfg(test)]
fn flush(&mut self) -> impl std::future::Future<Output = io::Result<()>> + '_ {
futures_util::future::poll_fn(move |cx| self.poll_flush(cx))
std::future::poll_fn(move |cx| self.poll_flush(cx))
}
}

Expand Down Expand Up @@ -668,7 +667,7 @@ mod tests {
// // First, let's just check that the Mock would normally return an
// // error on an unexpected write, even if the buffer is empty...
// let mut mock = Mock::new().build();
// futures_util::future::poll_fn(|cx| {
// std::future::poll_fn(|cx| {
// Pin::new(&mut mock).poll_write_buf(cx, &mut Cursor::new(&[]))
// })
// .await
Expand Down Expand Up @@ -700,7 +699,7 @@ mod tests {

// We expect a `parse` to be not ready, and so can't await it directly.
// Rather, this `poll_fn` will wrap the `Poll` result.
futures_util::future::poll_fn(|cx| {
std::future::poll_fn(|cx| {
let parse_ctx = ParseContext {
cached_headers: &mut None,
req_method: &mut None,
Expand Down
3 changes: 1 addition & 2 deletions src/proto/h2/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{
future::Future,
marker::PhantomData,
pin::Pin,
task::{Context, Poll},
task::{ready, Context, Poll},
time::Duration,
};

Expand All @@ -12,7 +12,6 @@ use bytes::Bytes;
use futures_channel::mpsc::{Receiver, Sender};
use futures_channel::{mpsc, oneshot};
use futures_util::future::{Either, FusedFuture, FutureExt as _};
use futures_util::ready;
use futures_util::stream::{StreamExt as _, StreamFuture};
use h2::client::{Builder, Connection, SendRequest};
use h2::SendStream;
Expand Down
3 changes: 1 addition & 2 deletions src/proto/h2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ use std::future::Future;
use std::io::{Cursor, IoSlice};
use std::mem;
use std::pin::Pin;
use std::task::{Context, Poll};
use std::task::{ready, Context, Poll};

use bytes::{Buf, Bytes};
use futures_util::ready;
use h2::{Reason, RecvStream, SendStream};
use http::header::{HeaderName, CONNECTION, TE, TRANSFER_ENCODING, UPGRADE};
use http::HeaderMap;
Expand Down
3 changes: 1 addition & 2 deletions src/proto/h2/server.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use std::error::Error as StdError;
use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll};
use std::task::{ready, Context, Poll};
use std::time::Duration;

use bytes::Bytes;
use futures_util::ready;
use h2::server::{Connection, Handshake, SendResponse};
use h2::{Reason, RecvStream};
use http::{Method, Request};
Expand Down
5 changes: 2 additions & 3 deletions src/server/conn/http1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ use std::fmt;
use std::future::Future;
use std::pin::Pin;
use std::sync::Arc;
use std::task::{Context, Poll};
use std::task::{ready, Context, Poll};
use std::time::Duration;

use crate::rt::{Read, Write};
use crate::upgrade::Upgraded;
use bytes::Bytes;
use futures_util::ready;

use crate::body::{Body, Incoming as IncomingBody};
use crate::proto;
Expand Down Expand Up @@ -179,7 +178,7 @@ where
/// This errors if the underlying connection protocol is not HTTP/1.
pub fn without_shutdown(self) -> impl Future<Output = crate::Result<Parts<I, S>>> {
let mut zelf = Some(self);
futures_util::future::poll_fn(move |cx| {
std::future::poll_fn(move |cx| {
ready!(zelf.as_mut().unwrap().conn.poll_without_shutdown(cx))?;
Poll::Ready(Ok(zelf.take().unwrap().into_parts()))
})
Expand Down
3 changes: 1 addition & 2 deletions src/server/conn/http2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ use std::fmt;
use std::future::Future;
use std::pin::Pin;
use std::sync::Arc;
use std::task::{Context, Poll};
use std::task::{ready, Context, Poll};
use std::time::Duration;

use crate::rt::{Read, Write};
use futures_util::ready;
use pin_project_lite::pin_project;

use crate::body::{Body, Incoming as IncomingBody};
Expand Down
3 changes: 2 additions & 1 deletion tests/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1486,6 +1486,7 @@ test! {

mod conn {
use std::error::Error;
use std::future::poll_fn;
use std::io::{self, Read, Write};
use std::net::{SocketAddr, TcpListener};
use std::pin::Pin;
Expand All @@ -1495,7 +1496,7 @@ mod conn {

use bytes::{Buf, Bytes};
use futures_channel::{mpsc, oneshot};
use futures_util::future::{self, poll_fn, FutureExt, TryFutureExt};
use futures_util::future::{self, FutureExt, TryFutureExt};
use http_body_util::{BodyExt, Empty, Full, StreamBody};
use hyper::rt::Timer;
use tokio::io::{AsyncReadExt as _, AsyncWriteExt as _};
Expand Down
Loading