Skip to content

Commit 8e6095e

Browse files
authored
refactor(common): remove common re-export (#3391)
1 parent 06137bc commit 8e6095e

34 files changed

+275
-239
lines changed

src/body/body.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ use std::borrow::Cow;
22
#[cfg(feature = "stream")]
33
use std::error::Error as StdError;
44
use std::fmt;
5+
use std::future::Future;
6+
use std::pin::Pin;
7+
use std::task::{Context, Poll};
58

69
use bytes::Bytes;
710
use futures_channel::mpsc;
@@ -15,10 +18,9 @@ use http_body::{Body as HttpBody, SizeHint};
1518
use super::DecodedLength;
1619
#[cfg(feature = "stream")]
1720
use crate::common::sync_wrapper::SyncWrapper;
18-
use crate::common::Future;
21+
use crate::common::watch;
1922
#[cfg(all(feature = "client", any(feature = "http1", feature = "http2")))]
2023
use crate::common::Never;
21-
use crate::common::{task, watch, Pin, Poll};
2224
#[cfg(all(feature = "http2", any(feature = "client", feature = "server")))]
2325
use crate::proto::h2::ping;
2426

@@ -239,7 +241,7 @@ impl Body {
239241
.get_or_insert_with(|| Box::new(Extra { delayed_eof: None }))
240242
}
241243

242-
fn poll_eof(&mut self, cx: &mut task::Context<'_>) -> Poll<Option<crate::Result<Bytes>>> {
244+
fn poll_eof(&mut self, cx: &mut Context<'_>) -> Poll<Option<crate::Result<Bytes>>> {
243245
match self.take_delayed_eof() {
244246
#[cfg(any(feature = "http1", feature = "http2"))]
245247
#[cfg(feature = "client")]
@@ -292,7 +294,7 @@ impl Body {
292294
}
293295
}
294296

295-
fn poll_inner(&mut self, cx: &mut task::Context<'_>) -> Poll<Option<crate::Result<Bytes>>> {
297+
fn poll_inner(&mut self, cx: &mut Context<'_>) -> Poll<Option<crate::Result<Bytes>>> {
296298
match self.kind {
297299
Kind::Once(ref mut val) => Poll::Ready(val.take().map(Ok)),
298300
Kind::Chan {
@@ -367,14 +369,14 @@ impl HttpBody for Body {
367369

368370
fn poll_data(
369371
mut self: Pin<&mut Self>,
370-
cx: &mut task::Context<'_>,
372+
cx: &mut Context<'_>,
371373
) -> Poll<Option<Result<Self::Data, Self::Error>>> {
372374
self.poll_eof(cx)
373375
}
374376

375377
fn poll_trailers(
376378
#[cfg_attr(not(feature = "http2"), allow(unused_mut))] mut self: Pin<&mut Self>,
377-
#[cfg_attr(not(feature = "http2"), allow(unused))] cx: &mut task::Context<'_>,
379+
#[cfg_attr(not(feature = "http2"), allow(unused))] cx: &mut Context<'_>,
378380
) -> Poll<Result<Option<HeaderMap>, Self::Error>> {
379381
match self.kind {
380382
#[cfg(all(feature = "http2", any(feature = "client", feature = "server")))]
@@ -470,7 +472,7 @@ impl fmt::Debug for Body {
470472
impl Stream for Body {
471473
type Item = crate::Result<Bytes>;
472474

473-
fn poll_next(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Option<Self::Item>> {
475+
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
474476
HttpBody::poll_data(self, cx)
475477
}
476478
}
@@ -550,15 +552,15 @@ impl From<Cow<'static, str>> for Body {
550552

551553
impl Sender {
552554
/// Check to see if this `Sender` can send more data.
553-
pub fn poll_ready(&mut self, cx: &mut task::Context<'_>) -> Poll<crate::Result<()>> {
555+
pub fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<crate::Result<()>> {
554556
// Check if the receiver end has tried polling for the body yet
555557
ready!(self.poll_want(cx)?);
556558
self.data_tx
557559
.poll_ready(cx)
558560
.map_err(|_| crate::Error::new_closed())
559561
}
560562

561-
fn poll_want(&mut self, cx: &mut task::Context<'_>) -> Poll<crate::Result<()>> {
563+
fn poll_want(&mut self, cx: &mut Context<'_>) -> Poll<crate::Result<()>> {
562564
match self.want_rx.load(cx) {
563565
WANT_READY => Poll::Ready(Ok(())),
564566
WANT_PENDING => Poll::Pending,

src/client/client.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
use std::error::Error as StdError;
22
use std::fmt;
3+
use std::future::Future;
4+
use std::marker::Unpin;
35
use std::mem;
6+
use std::pin::Pin;
7+
use std::task::{Context, Poll};
48
use std::time::Duration;
59

610
use futures_channel::oneshot;
@@ -12,10 +16,7 @@ use tracing::{debug, trace, warn};
1216

1317
use crate::body::{Body, HttpBody};
1418
use crate::client::connect::CaptureConnectionExtension;
15-
use crate::common::{
16-
exec::BoxSendFuture, lazy as hyper_lazy, sync_wrapper::SyncWrapper, task, Future, Lazy, Pin,
17-
Poll,
18-
};
19+
use crate::common::{exec::BoxSendFuture, lazy as hyper_lazy, sync_wrapper::SyncWrapper, Lazy};
1920
#[cfg(feature = "http2")]
2021
use crate::ext::Protocol;
2122
use crate::rt::Executor;
@@ -553,7 +554,7 @@ where
553554
type Error = crate::Error;
554555
type Future = ResponseFuture;
555556

556-
fn poll_ready(&mut self, _: &mut task::Context<'_>) -> Poll<Result<(), Self::Error>> {
557+
fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
557558
Poll::Ready(Ok(()))
558559
}
559560

@@ -573,7 +574,7 @@ where
573574
type Error = crate::Error;
574575
type Future = ResponseFuture;
575576

576-
fn poll_ready(&mut self, _: &mut task::Context<'_>) -> Poll<Result<(), Self::Error>> {
577+
fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
577578
Poll::Ready(Ok(()))
578579
}
579580

@@ -628,7 +629,7 @@ impl fmt::Debug for ResponseFuture {
628629
impl Future for ResponseFuture {
629630
type Output = crate::Result<Response<Body>>;
630631

631-
fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output> {
632+
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
632633
self.inner.get_mut().as_mut().poll(cx)
633634
}
634635
}
@@ -650,7 +651,7 @@ enum PoolTx<B> {
650651
}
651652

652653
impl<B> PoolClient<B> {
653-
fn poll_ready(&mut self, cx: &mut task::Context<'_>) -> Poll<crate::Result<()>> {
654+
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<crate::Result<()>> {
654655
match self.tx {
655656
PoolTx::Http1(ref mut tx) => tx.poll_ready(cx),
656657
#[cfg(feature = "http2")]

src/client/conn.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,13 @@ pub mod http2;
6161

6262
use std::error::Error as StdError;
6363
use std::fmt;
64+
use std::future::Future;
6465
#[cfg(not(all(feature = "http1", feature = "http2")))]
6566
use std::marker::PhantomData;
67+
use std::marker::Unpin;
68+
use std::pin::Pin;
6669
use std::sync::Arc;
70+
use std::task::{Context, Poll};
6771
#[cfg(all(feature = "runtime", feature = "http2"))]
6872
use std::time::Duration;
6973

@@ -77,12 +81,9 @@ use tracing::{debug, trace};
7781

7882
use super::dispatch;
7983
use crate::body::HttpBody;
84+
use crate::common::exec::{BoxSendFuture, Exec};
8085
#[cfg(not(all(feature = "http1", feature = "http2")))]
8186
use crate::common::Never;
82-
use crate::common::{
83-
exec::{BoxSendFuture, Exec},
84-
task, Future, Pin, Poll,
85-
};
8687
use crate::proto;
8788
use crate::rt::Executor;
8889
#[cfg(feature = "http1")]
@@ -257,7 +258,7 @@ impl<B> SendRequest<B> {
257258
/// Polls to determine whether this sender can be used yet for a request.
258259
///
259260
/// If the associated connection is closed, this returns an Error.
260-
pub fn poll_ready(&mut self, cx: &mut task::Context<'_>) -> Poll<crate::Result<()>> {
261+
pub fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<crate::Result<()>> {
261262
self.dispatch.poll_ready(cx)
262263
}
263264

@@ -381,7 +382,7 @@ where
381382
type Error = crate::Error;
382383
type Future = ResponseFuture;
383384

384-
fn poll_ready(&mut self, cx: &mut task::Context<'_>) -> Poll<Result<(), Self::Error>> {
385+
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
385386
self.poll_ready(cx)
386387
}
387388

@@ -502,7 +503,7 @@ where
502503
/// Use [`poll_fn`](https://docs.rs/futures/0.1.25/futures/future/fn.poll_fn.html)
503504
/// and [`try_ready!`](https://docs.rs/futures/0.1.25/futures/macro.try_ready.html)
504505
/// to work with this function; or use the `without_shutdown` wrapper.
505-
pub fn poll_without_shutdown(&mut self, cx: &mut task::Context<'_>) -> Poll<crate::Result<()>> {
506+
pub fn poll_without_shutdown(&mut self, cx: &mut Context<'_>) -> Poll<crate::Result<()>> {
506507
match *self.inner.as_mut().expect("already upgraded") {
507508
#[cfg(feature = "http1")]
508509
ProtoClient::H1 { ref mut h1 } => h1.poll_without_shutdown(cx),
@@ -554,7 +555,7 @@ where
554555
{
555556
type Output = crate::Result<()>;
556557

557-
fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output> {
558+
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
558559
match ready!(Pin::new(self.inner.as_mut().unwrap()).poll(cx))? {
559560
proto::Dispatched::Shutdown => Poll::Ready(Ok(())),
560561
#[cfg(feature = "http1")]
@@ -1067,7 +1068,7 @@ impl Builder {
10671068
impl Future for ResponseFuture {
10681069
type Output = crate::Result<Response<Body>>;
10691070

1070-
fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output> {
1071+
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
10711072
match self.inner {
10721073
ResponseFutureState::Waiting(ref mut rx) => {
10731074
Pin::new(rx).poll(cx).map(|res| match res {
@@ -1101,7 +1102,7 @@ where
11011102
{
11021103
type Output = crate::Result<proto::Dispatched>;
11031104

1104-
fn poll(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output> {
1105+
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
11051106
match self.project() {
11061107
#[cfg(feature = "http1")]
11071108
ProtoClientProj::H1 { h1 } => h1.poll(cx),

src/client/conn/http1.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
33
use std::error::Error as StdError;
44
use std::fmt;
5+
use std::future::Future;
6+
use std::marker::Unpin;
7+
use std::pin::Pin;
8+
use std::task::{Context, Poll};
59

610
use bytes::Bytes;
711
use http::{Request, Response};
@@ -10,7 +14,6 @@ use tokio::io::{AsyncRead, AsyncWrite};
1014

1115
use super::super::dispatch;
1216
use crate::body::{Body as IncomingBody, HttpBody as Body};
13-
use crate::common::{task, Future, Pin, Poll};
1417
use crate::proto;
1518
use crate::upgrade::Upgraded;
1619

@@ -84,7 +87,7 @@ where
8487
/// Use [`poll_fn`](https://docs.rs/futures/0.1.25/futures/future/fn.poll_fn.html)
8588
/// and [`try_ready!`](https://docs.rs/futures/0.1.25/futures/macro.try_ready.html)
8689
/// to work with this function; or use the `without_shutdown` wrapper.
87-
pub fn poll_without_shutdown(&mut self, cx: &mut task::Context<'_>) -> Poll<crate::Result<()>> {
90+
pub fn poll_without_shutdown(&mut self, cx: &mut Context<'_>) -> Poll<crate::Result<()>> {
8891
self.inner
8992
.as_mut()
9093
.expect("algready upgraded")
@@ -128,7 +131,7 @@ impl<B> SendRequest<B> {
128131
/// Polls to determine whether this sender can be used yet for a request.
129132
///
130133
/// If the associated connection is closed, this returns an Error.
131-
pub fn poll_ready(&mut self, cx: &mut task::Context<'_>) -> Poll<crate::Result<()>> {
134+
pub fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<crate::Result<()>> {
132135
self.dispatch.poll_ready(cx)
133136
}
134137

@@ -258,7 +261,7 @@ where
258261
{
259262
type Output = crate::Result<()>;
260263

261-
fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output> {
264+
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
262265
match ready!(Pin::new(self.inner.as_mut().unwrap()).poll(cx))? {
263266
proto::Dispatched::Shutdown => Poll::Ready(Ok(())),
264267
proto::Dispatched::Upgrade(pending) => match self.inner.take() {

src/client/conn/http2.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@
22
33
use std::error::Error as StdError;
44
use std::fmt;
5+
use std::future::Future;
56
use std::marker::PhantomData;
7+
use std::marker::Unpin;
8+
use std::pin::Pin;
69
use std::sync::Arc;
10+
use std::task::{Context, Poll};
711
use std::time::Duration;
812

913
use http::{Request, Response};
1014
use tokio::io::{AsyncRead, AsyncWrite};
1115

1216
use super::super::dispatch;
1317
use crate::body::{Body as IncomingBody, HttpBody as Body};
14-
use crate::common::{
15-
exec::{BoxSendFuture, Exec},
16-
task, Future, Pin, Poll,
17-
};
18+
use crate::common::exec::{BoxSendFuture, Exec};
1819
use crate::proto;
1920
use crate::rt::Executor;
2021

@@ -74,7 +75,7 @@ impl<B> SendRequest<B> {
7475
/// Polls to determine whether this sender can be used yet for a request.
7576
///
7677
/// If the associated connection is closed, this returns an Error.
77-
pub fn poll_ready(&mut self, _cx: &mut task::Context<'_>) -> Poll<crate::Result<()>> {
78+
pub fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<crate::Result<()>> {
7879
if self.is_closed() {
7980
Poll::Ready(Err(crate::Error::new_closed()))
8081
} else {
@@ -229,7 +230,7 @@ where
229230
{
230231
type Output = crate::Result<()>;
231232

232-
fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output> {
233+
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
233234
match ready!(Pin::new(&mut self.inner.1).poll(cx))? {
234235
proto::Dispatched::Shutdown => Poll::Ready(Ok(())),
235236
#[cfg(feature = "http1")]

src/client/connect/dns.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use std::future::Future;
2626
use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6, ToSocketAddrs};
2727
use std::pin::Pin;
2828
use std::str::FromStr;
29-
use std::task::{self, Poll};
29+
use std::task::{Context, Poll};
3030
use std::{fmt, io, vec};
3131

3232
use tokio::task::JoinHandle;
@@ -113,7 +113,7 @@ impl Service<Name> for GaiResolver {
113113
type Error = io::Error;
114114
type Future = GaiFuture;
115115

116-
fn poll_ready(&mut self, _cx: &mut task::Context<'_>) -> Poll<Result<(), io::Error>> {
116+
fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), io::Error>> {
117117
Poll::Ready(Ok(()))
118118
}
119119

@@ -138,7 +138,7 @@ impl fmt::Debug for GaiResolver {
138138
impl Future for GaiFuture {
139139
type Output = Result<GaiAddrs, io::Error>;
140140

141-
fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output> {
141+
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
142142
Pin::new(&mut self.inner).poll(cx).map(|res| match res {
143143
Ok(Ok(addrs)) => Ok(GaiAddrs { inner: addrs }),
144144
Ok(Err(err)) => Err(err),
@@ -286,7 +286,7 @@ impl Service<Name> for TokioThreadpoolGaiResolver {
286286
type Error = io::Error;
287287
type Future = TokioThreadpoolGaiFuture;
288288
289-
fn poll_ready(&mut self, _cx: &mut task::Context<'_>) -> Poll<Result<(), io::Error>> {
289+
fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), io::Error>> {
290290
Poll::Ready(Ok(()))
291291
}
292292
@@ -299,7 +299,7 @@ impl Service<Name> for TokioThreadpoolGaiResolver {
299299
impl Future for TokioThreadpoolGaiFuture {
300300
type Output = Result<GaiAddrs, io::Error>;
301301
302-
fn poll(self: Pin<&mut Self>, _cx: &mut task::Context<'_>) -> Poll<Self::Output> {
302+
fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Self::Output> {
303303
match ready!(tokio_executor::threadpool::blocking(|| (
304304
self.name.as_str(),
305305
0
@@ -318,8 +318,10 @@ impl Future for TokioThreadpoolGaiFuture {
318318
*/
319319

320320
mod sealed {
321+
use std::future::Future;
322+
use std::task::{Context, Poll};
323+
321324
use super::{Name, SocketAddr};
322-
use crate::common::{task, Future, Poll};
323325
use tower_service::Service;
324326

325327
// "Trait alias" for `Service<Name, Response = Addrs>`
@@ -328,7 +330,7 @@ mod sealed {
328330
type Error: Into<Box<dyn std::error::Error + Send + Sync>>;
329331
type Future: Future<Output = Result<Self::Addrs, Self::Error>>;
330332

331-
fn poll_ready(&mut self, cx: &mut task::Context<'_>) -> Poll<Result<(), Self::Error>>;
333+
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>;
332334
fn resolve(&mut self, name: Name) -> Self::Future;
333335
}
334336

@@ -342,7 +344,7 @@ mod sealed {
342344
type Error = S::Error;
343345
type Future = S::Future;
344346

345-
fn poll_ready(&mut self, cx: &mut task::Context<'_>) -> Poll<Result<(), Self::Error>> {
347+
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
346348
Service::poll_ready(self, cx)
347349
}
348350

0 commit comments

Comments
 (0)