Skip to content

Commit 1b6dfa8

Browse files
refactor: reduce dependency on futures-util
1 parent 24714a3 commit 1b6dfa8

File tree

6 files changed

+21
-35
lines changed

6 files changed

+21
-35
lines changed

src/client/legacy/connect/http.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::future::Future;
44
use std::io;
55
use std::marker::PhantomData;
66
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr};
7-
use std::pin::Pin;
7+
use std::pin::{pin, Pin};
88
use std::sync::Arc;
99
use std::task::{self, Poll};
1010
use std::time::Duration;
@@ -970,14 +970,11 @@ impl ConnectingTcp<'_> {
970970
match self.fallback {
971971
None => self.preferred.connect(self.config).await,
972972
Some(mut fallback) => {
973-
let preferred_fut = self.preferred.connect(self.config);
974-
futures_util::pin_mut!(preferred_fut);
973+
let preferred_fut = pin!(self.preferred.connect(self.config));
975974

976-
let fallback_fut = fallback.remote.connect(self.config);
977-
futures_util::pin_mut!(fallback_fut);
975+
let fallback_fut = pin!(fallback.remote.connect(self.config));
978976

979-
let fallback_delay = fallback.delay;
980-
futures_util::pin_mut!(fallback_delay);
977+
let fallback_delay = pin!(fallback.delay);
981978

982979
let (result, future) =
983980
match futures_util::future::select(preferred_fut, fallback_delay).await {

src/client/legacy/pool.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ use std::hash::Hash;
99
use std::ops::{Deref, DerefMut};
1010
use std::pin::Pin;
1111
use std::sync::{Arc, Mutex, Weak};
12-
use std::task::{self, Poll};
12+
use std::task::{self, ready, Poll};
1313

1414
use std::time::{Duration, Instant};
1515

1616
use futures_channel::oneshot;
17-
use futures_core::ready;
1817
use tracing::{debug, trace};
1918

2019
use hyper::rt::Timer as _;

src/server/conn/auto/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ use std::future::Future;
77
use std::marker::PhantomPinned;
88
use std::mem::MaybeUninit;
99
use std::pin::Pin;
10-
use std::task::{Context, Poll};
10+
use std::task::{ready, Context, Poll};
1111
use std::{error::Error as StdError, io, time::Duration};
1212

1313
use bytes::Bytes;
14-
use futures_core::ready;
1514
use http::{Request, Response};
1615
use http_body::Body;
1716
use hyper::{

src/service/oneshot.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
use futures_core::ready;
21
use pin_project_lite::pin_project;
32
use std::future::Future;
43
use std::pin::Pin;
5-
use std::task::{Context, Poll};
4+
use std::task::{ready, Context, Poll};
65
use tower_service::Service;
76

87
// Vendored from tower::util to reduce dependencies, the code is small enough.

tests/legacy_client.rs

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
mod test_utils;
22

3+
use std::future::Future;
34
use std::io::{Read, Write};
45
use std::net::{SocketAddr, TcpListener};
5-
use std::pin::Pin;
6+
use std::pin::{pin, Pin};
67
use std::sync::atomic::Ordering;
78
use std::sync::Arc;
89
use std::task::Poll;
910
use std::thread;
1011
use std::time::Duration;
1112

1213
use futures_channel::{mpsc, oneshot};
14+
use futures_core::Stream;
1315
use futures_util::future::{self, FutureExt, TryFutureExt};
1416
use futures_util::stream::StreamExt;
15-
use futures_util::{self, Stream};
1617
use http_body_util::BodyExt;
1718
use http_body_util::{Empty, Full, StreamBody};
1819
use tokio::io::{AsyncReadExt, AsyncWriteExt};
@@ -132,7 +133,7 @@ async fn drop_client_closes_idle_connections() {
132133
res.unwrap();
133134

134135
// not closed yet, just idle
135-
future::poll_fn(|ctx| {
136+
std::future::poll_fn(|ctx| {
136137
assert!(Pin::new(&mut closes).poll_next(ctx).is_pending());
137138
Poll::Ready(())
138139
})
@@ -142,8 +143,7 @@ async fn drop_client_closes_idle_connections() {
142143
drop(client);
143144

144145
// and wait a few ticks for the connections to close
145-
let t = tokio::time::sleep(Duration::from_millis(100)).map(|_| panic!("time out"));
146-
futures_util::pin_mut!(t);
146+
let t = pin!(tokio::time::sleep(Duration::from_millis(100)).map(|_| panic!("time out")));
147147
let close = closes.into_future().map(|(opt, _)| opt.expect("closes"));
148148
future::select(t, close).await;
149149
t1.await.unwrap();
@@ -192,8 +192,7 @@ async fn drop_response_future_closes_in_progress_connection() {
192192
future::select(res, rx1).await;
193193

194194
// res now dropped
195-
let t = tokio::time::sleep(Duration::from_millis(100)).map(|_| panic!("time out"));
196-
futures_util::pin_mut!(t);
195+
let t = pin!(tokio::time::sleep(Duration::from_millis(100)).map(|_| panic!("time out")));
197196
let close = closes.into_future().map(|(opt, _)| opt.expect("closes"));
198197
future::select(t, close).await;
199198
}
@@ -248,8 +247,7 @@ async fn drop_response_body_closes_in_progress_connection() {
248247
res.unwrap();
249248

250249
// and wait a few ticks to see the connection drop
251-
let t = tokio::time::sleep(Duration::from_millis(100)).map(|_| panic!("time out"));
252-
futures_util::pin_mut!(t);
250+
let t = pin!(tokio::time::sleep(Duration::from_millis(100)).map(|_| panic!("time out")));
253251
let close = closes.into_future().map(|(opt, _)| opt.expect("closes"));
254252
future::select(t, close).await;
255253
}
@@ -301,8 +299,7 @@ async fn no_keep_alive_closes_connection() {
301299
let (res, _) = future::join(res, rx).await;
302300
res.unwrap();
303301

304-
let t = tokio::time::sleep(Duration::from_millis(100)).map(|_| panic!("time out"));
305-
futures_util::pin_mut!(t);
302+
let t = pin!(tokio::time::sleep(Duration::from_millis(100)).map(|_| panic!("time out")));
306303
let close = closes.into_future().map(|(opt, _)| opt.expect("closes"));
307304
future::select(close, t).await;
308305
}
@@ -348,8 +345,7 @@ async fn socket_disconnect_closes_idle_conn() {
348345
let (res, _) = future::join(res, rx).await;
349346
res.unwrap();
350347

351-
let t = tokio::time::sleep(Duration::from_millis(100)).map(|_| panic!("time out"));
352-
futures_util::pin_mut!(t);
348+
let t = pin!(tokio::time::sleep(Duration::from_millis(100)).map(|_| panic!("time out")));
353349
let close = closes.into_future().map(|(opt, _)| opt.expect("closes"));
354350
future::select(t, close).await;
355351
}
@@ -562,7 +558,7 @@ async fn client_keep_alive_when_response_before_request_body_ends() {
562558
});
563559

564560
future::join(res, rx2).await.0.unwrap();
565-
future::poll_fn(|ctx| {
561+
std::future::poll_fn(|ctx| {
566562
assert!(Pin::new(&mut closes).poll_next(ctx).is_pending());
567563
Poll::Ready(())
568564
})
@@ -571,8 +567,7 @@ async fn client_keep_alive_when_response_before_request_body_ends() {
571567
assert_eq!(connects.load(Ordering::Relaxed), 1);
572568

573569
drop(client);
574-
let t = tokio::time::sleep(Duration::from_millis(100)).map(|_| panic!("time out"));
575-
futures_util::pin_mut!(t);
570+
let t = pin!(tokio::time::sleep(Duration::from_millis(100)).map(|_| panic!("time out")));
576571
let close = closes.into_future().map(|(opt, _)| opt.expect("closes"));
577572
future::select(t, close).await;
578573
}
@@ -1255,10 +1250,7 @@ impl tower_service::Service<hyper::Uri> for MockConnector {
12551250
type Response = crate::MockConnection;
12561251
type Error = std::io::Error;
12571252
type Future = std::pin::Pin<
1258-
Box<
1259-
dyn futures_util::Future<Output = std::result::Result<Self::Response, Self::Error>>
1260-
+ Send,
1261-
>,
1253+
Box<dyn Future<Output = std::result::Result<Self::Response, Self::Error>> + Send>,
12621254
>;
12631255

12641256
// Polls the connector to check if it’s ready to handle a request.

tests/test_utils/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
use std::future::Future;
12
use std::pin::Pin;
23
use std::sync::atomic::{AtomicUsize, Ordering};
34
use std::sync::Arc;
5+
use std::task::{Context, Poll};
46

57
use futures_channel::mpsc;
6-
use futures_util::task::{Context, Poll};
7-
use futures_util::Future;
88
use futures_util::TryFutureExt;
99
use hyper::Uri;
1010
use tokio::io::{self, AsyncRead, AsyncWrite, ReadBuf};

0 commit comments

Comments
 (0)