Skip to content

Commit d9216c3

Browse files
authored
refactor(common): remove common re-export (#3346)
1 parent 8ebe25c commit d9216c3

File tree

19 files changed

+156
-151
lines changed

19 files changed

+156
-151
lines changed

src/body/incoming.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
use std::fmt;
2+
use std::future::Future;
3+
use std::pin::Pin;
4+
use std::task::{Context, Poll};
25

36
use bytes::Bytes;
47
use futures_channel::mpsc;
@@ -8,8 +11,7 @@ use http::HeaderMap;
811
use http_body::{Body, Frame, SizeHint};
912

1013
use super::DecodedLength;
11-
use crate::common::Future;
12-
use crate::common::{task, watch, Pin, Poll};
14+
use crate::common::watch;
1315
#[cfg(all(feature = "http2", any(feature = "client", feature = "server")))]
1416
use crate::proto::h2::ping;
1517

@@ -157,7 +159,7 @@ impl Body for Incoming {
157159

158160
fn poll_frame(
159161
mut self: Pin<&mut Self>,
160-
cx: &mut task::Context<'_>,
162+
cx: &mut Context<'_>,
161163
) -> Poll<Option<Result<Frame<Self::Data>, Self::Error>>> {
162164
match self.kind {
163165
Kind::Empty => Poll::Ready(None),
@@ -287,15 +289,15 @@ impl fmt::Debug for Incoming {
287289

288290
impl Sender {
289291
/// Check to see if this `Sender` can send more data.
290-
pub(crate) fn poll_ready(&mut self, cx: &mut task::Context<'_>) -> Poll<crate::Result<()>> {
292+
pub(crate) fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<crate::Result<()>> {
291293
// Check if the receiver end has tried polling for the body yet
292294
ready!(self.poll_want(cx)?);
293295
self.data_tx
294296
.poll_ready(cx)
295297
.map_err(|_| crate::Error::new_closed())
296298
}
297299

298-
fn poll_want(&mut self, cx: &mut task::Context<'_>) -> Poll<crate::Result<()>> {
300+
fn poll_want(&mut self, cx: &mut Context<'_>) -> Poll<crate::Result<()>> {
299301
match self.want_rx.load(cx) {
300302
WANT_READY => Poll::Ready(Ok(())),
301303
WANT_PENDING => Poll::Pending,

src/client/conn/http1.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
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 crate::rt::{Read, Write};
710
use bytes::Bytes;
@@ -10,7 +13,6 @@ use httparse::ParserConfig;
1013

1114
use super::super::dispatch;
1215
use crate::body::{Body, Incoming as IncomingBody};
13-
use crate::common::{task, Future, Pin, Poll};
1416
use crate::proto;
1517
use crate::upgrade::Upgraded;
1618

@@ -84,7 +86,7 @@ where
8486
/// Use [`poll_fn`](https://docs.rs/futures/0.1.25/futures/future/fn.poll_fn.html)
8587
/// and [`try_ready!`](https://docs.rs/futures/0.1.25/futures/macro.try_ready.html)
8688
/// 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<()>> {
89+
pub fn poll_without_shutdown(&mut self, cx: &mut Context<'_>) -> Poll<crate::Result<()>> {
8890
self.inner
8991
.as_mut()
9092
.expect("already upgraded")
@@ -128,7 +130,7 @@ impl<B> SendRequest<B> {
128130
/// Polls to determine whether this sender can be used yet for a request.
129131
///
130132
/// If the associated connection is closed, this returns an Error.
131-
pub fn poll_ready(&mut self, cx: &mut task::Context<'_>) -> Poll<crate::Result<()>> {
133+
pub fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<crate::Result<()>> {
132134
self.dispatch.poll_ready(cx)
133135
}
134136

@@ -254,7 +256,7 @@ where
254256
{
255257
type Output = crate::Result<()>;
256258

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

src/client/conn/http2.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
33
use std::error::Error;
44
use std::fmt;
5+
use std::future::Future;
56
use std::marker::PhantomData;
7+
use std::pin::Pin;
68
use std::sync::Arc;
9+
use std::task::{Context, Poll};
710
use std::time::Duration;
811

912
use crate::rt::{Read, Write};
@@ -12,7 +15,6 @@ use http::{Request, Response};
1215
use super::super::dispatch;
1316
use crate::body::{Body, Incoming as IncomingBody};
1417
use crate::common::time::Time;
15-
use crate::common::{task, Future, Pin, Poll};
1618
use crate::proto;
1719
use crate::rt::bounds::ExecutorClient;
1820
use crate::rt::Timer;
@@ -79,7 +81,7 @@ impl<B> SendRequest<B> {
7981
/// Polls to determine whether this sender can be used yet for a request.
8082
///
8183
/// If the associated connection is closed, this returns an Error.
82-
pub fn poll_ready(&mut self, _cx: &mut task::Context<'_>) -> Poll<crate::Result<()>> {
84+
pub fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<crate::Result<()>> {
8385
if self.is_closed() {
8486
Poll::Ready(Err(crate::Error::new_closed()))
8587
} else {
@@ -236,7 +238,7 @@ where
236238
{
237239
type Output = crate::Result<()>;
238240

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

src/client/dispatch.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
use std::task::{Context, Poll};
12
#[cfg(feature = "http2")]
2-
use std::future::Future;
3+
use std::{future::Future, pin::Pin};
34

45
#[cfg(feature = "http2")]
56
use http::{Request, Response};
@@ -9,9 +10,8 @@ use http_body::Body;
910
use pin_project_lite::pin_project;
1011
use tokio::sync::{mpsc, oneshot};
1112

12-
use crate::common::{task, Poll};
1313
#[cfg(feature = "http2")]
14-
use crate::{body::Incoming, common::Pin, proto::h2::client::ResponseFutMap};
14+
use crate::{body::Incoming, proto::h2::client::ResponseFutMap};
1515

1616
#[cfg(test)]
1717
pub(crate) type RetryPromise<T, U> = oneshot::Receiver<Result<U, (crate::Error, Option<T>)>>;
@@ -62,7 +62,7 @@ pub(crate) struct UnboundedSender<T, U> {
6262

6363
impl<T, U> Sender<T, U> {
6464
#[cfg(feature = "http1")]
65-
pub(crate) fn poll_ready(&mut self, cx: &mut task::Context<'_>) -> Poll<crate::Result<()>> {
65+
pub(crate) fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<crate::Result<()>> {
6666
self.giver
6767
.poll_want(cx)
6868
.map_err(|_| crate::Error::new_closed())
@@ -169,10 +169,7 @@ pub(crate) struct Receiver<T, U> {
169169
}
170170

171171
impl<T, U> Receiver<T, U> {
172-
pub(crate) fn poll_recv(
173-
&mut self,
174-
cx: &mut task::Context<'_>,
175-
) -> Poll<Option<(T, Callback<T, U>)>> {
172+
pub(crate) fn poll_recv(&mut self, cx: &mut Context<'_>) -> Poll<Option<(T, Callback<T, U>)>> {
176173
match self.inner.poll_recv(cx) {
177174
Poll::Ready(item) => {
178175
Poll::Ready(item.map(|mut env| env.0.take().expect("envelope not dropped")))
@@ -261,7 +258,7 @@ impl<T, U> Callback<T, U> {
261258
}
262259
}
263260

264-
pub(crate) fn poll_canceled(&mut self, cx: &mut task::Context<'_>) -> Poll<()> {
261+
pub(crate) fn poll_canceled(&mut self, cx: &mut Context<'_>) -> Poll<()> {
265262
match *self {
266263
Callback::Retry(Some(ref mut tx)) => tx.poll_closed(cx),
267264
Callback::NoRetry(Some(ref mut tx)) => tx.poll_closed(cx),
@@ -302,7 +299,7 @@ where
302299
{
303300
type Output = ();
304301

305-
fn poll(self: Pin<&mut Self>, cx: &mut std::task::Context<'_>) -> Poll<Self::Output> {
302+
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
306303
let mut this = self.project();
307304

308305
let mut call_back = this.call_back.take().expect("polled after complete");
@@ -319,7 +316,7 @@ where
319316
Poll::Pending => {
320317
// Move call_back back to struct before return
321318
this.call_back.set(Some(call_back));
322-
return std::task::Poll::Pending;
319+
return Poll::Pending;
323320
}
324321
};
325322
trace!("send_when canceled");

src/common/io/rewind.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use std::marker::Unpin;
2+
use std::pin::Pin;
3+
use std::task::{Context, Poll};
24
use std::{cmp, io};
35

46
use bytes::{Buf, Bytes};
57

6-
use crate::common::{task, Pin, Poll};
78
use crate::rt::{Read, ReadBufCursor, Write};
89

910
/// Combine a buffer with an IO, rewinding reads to use the buffer.
@@ -50,7 +51,7 @@ where
5051
{
5152
fn poll_read(
5253
mut self: Pin<&mut Self>,
53-
cx: &mut task::Context<'_>,
54+
cx: &mut Context<'_>,
5455
mut buf: ReadBufCursor<'_>,
5556
) -> Poll<io::Result<()>> {
5657
if let Some(mut prefix) = self.pre.take() {
@@ -78,25 +79,25 @@ where
7879
{
7980
fn poll_write(
8081
mut self: Pin<&mut Self>,
81-
cx: &mut task::Context<'_>,
82+
cx: &mut Context<'_>,
8283
buf: &[u8],
8384
) -> Poll<io::Result<usize>> {
8485
Pin::new(&mut self.inner).poll_write(cx, buf)
8586
}
8687

8788
fn poll_write_vectored(
8889
mut self: Pin<&mut Self>,
89-
cx: &mut task::Context<'_>,
90+
cx: &mut Context<'_>,
9091
bufs: &[io::IoSlice<'_>],
9192
) -> Poll<io::Result<usize>> {
9293
Pin::new(&mut self.inner).poll_write_vectored(cx, bufs)
9394
}
9495

95-
fn poll_flush(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<io::Result<()>> {
96+
fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
9697
Pin::new(&mut self.inner).poll_flush(cx)
9798
}
9899

99-
fn poll_shutdown(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<io::Result<()>> {
100+
fn poll_shutdown(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
100101
Pin::new(&mut self.inner).poll_shutdown(cx)
101102
}
102103

src/common/mod.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,3 @@ pub(crate) mod task;
2121
))]
2222
pub(crate) mod time;
2323
pub(crate) mod watch;
24-
25-
pub(crate) use self::task::Poll;
26-
27-
// group up types normally needed for `Future`
28-
pub(crate) use std::{future::Future, pin::Pin};

src/common/task.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
pub(crate) use std::task::{Context, Poll};
1+
#[cfg(all(any(feature = "client", feature = "server"), feature = "http1"))]
2+
use std::task::{Context, Poll};
23

34
/// A function to help "yield" a future, such that it is re-scheduled immediately.
45
///

src/proto/h1/conn.rs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use std::fmt;
22
use std::io;
33
use std::marker::{PhantomData, Unpin};
4+
use std::pin::Pin;
5+
use std::task::{Context, Poll};
46
#[cfg(feature = "server")]
57
use std::time::Duration;
68

@@ -15,7 +17,6 @@ use super::{Decoder, Encode, EncodedBuf, Encoder, Http1Transaction, ParseContext
1517
use crate::body::DecodedLength;
1618
#[cfg(feature = "server")]
1719
use crate::common::time::Time;
18-
use crate::common::{task, Pin, Poll};
1920
use crate::headers::connection_keep_alive;
2021
use crate::proto::{BodyLength, MessageHead};
2122
#[cfg(feature = "server")]
@@ -193,7 +194,7 @@ where
193194

194195
pub(super) fn poll_read_head(
195196
&mut self,
196-
cx: &mut task::Context<'_>,
197+
cx: &mut Context<'_>,
197198
) -> Poll<Option<crate::Result<(MessageHead<T::Incoming>, DecodedLength, Wants)>>> {
198199
debug_assert!(self.can_read_head());
199200
trace!("Conn::read_head");
@@ -294,7 +295,7 @@ where
294295

295296
pub(crate) fn poll_read_body(
296297
&mut self,
297-
cx: &mut task::Context<'_>,
298+
cx: &mut Context<'_>,
298299
) -> Poll<Option<io::Result<Bytes>>> {
299300
debug_assert!(self.can_read_body());
300301

@@ -355,10 +356,7 @@ where
355356
ret
356357
}
357358

358-
pub(crate) fn poll_read_keep_alive(
359-
&mut self,
360-
cx: &mut task::Context<'_>,
361-
) -> Poll<crate::Result<()>> {
359+
pub(crate) fn poll_read_keep_alive(&mut self, cx: &mut Context<'_>) -> Poll<crate::Result<()>> {
362360
debug_assert!(!self.can_read_head() && !self.can_read_body());
363361

364362
if self.is_read_closed() {
@@ -381,7 +379,7 @@ where
381379
//
382380
// This should only be called for Clients wanting to enter the idle
383381
// state.
384-
fn require_empty_read(&mut self, cx: &mut task::Context<'_>) -> Poll<crate::Result<()>> {
382+
fn require_empty_read(&mut self, cx: &mut Context<'_>) -> Poll<crate::Result<()>> {
385383
debug_assert!(!self.can_read_head() && !self.can_read_body() && !self.is_read_closed());
386384
debug_assert!(!self.is_mid_message());
387385
debug_assert!(T::is_client());
@@ -414,7 +412,7 @@ where
414412
Poll::Ready(Err(crate::Error::new_unexpected_message()))
415413
}
416414

417-
fn mid_message_detect_eof(&mut self, cx: &mut task::Context<'_>) -> Poll<crate::Result<()>> {
415+
fn mid_message_detect_eof(&mut self, cx: &mut Context<'_>) -> Poll<crate::Result<()>> {
418416
debug_assert!(!self.can_read_head() && !self.can_read_body() && !self.is_read_closed());
419417
debug_assert!(self.is_mid_message());
420418

@@ -433,7 +431,7 @@ where
433431
}
434432
}
435433

436-
fn force_io_read(&mut self, cx: &mut task::Context<'_>) -> Poll<io::Result<usize>> {
434+
fn force_io_read(&mut self, cx: &mut Context<'_>) -> Poll<io::Result<usize>> {
437435
debug_assert!(!self.state.is_read_closed());
438436

439437
let result = ready!(self.io.poll_read_from_io(cx));
@@ -444,7 +442,7 @@ where
444442
}))
445443
}
446444

447-
fn maybe_notify(&mut self, cx: &mut task::Context<'_>) {
445+
fn maybe_notify(&mut self, cx: &mut Context<'_>) {
448446
// its possible that we returned NotReady from poll() without having
449447
// exhausted the underlying Io. We would have done this when we
450448
// determined we couldn't keep reading until we knew how writing
@@ -491,7 +489,7 @@ where
491489
}
492490
}
493491

494-
fn try_keep_alive(&mut self, cx: &mut task::Context<'_>) {
492+
fn try_keep_alive(&mut self, cx: &mut Context<'_>) {
495493
self.state.try_keep_alive::<T>();
496494
self.maybe_notify(cx);
497495
}
@@ -716,14 +714,14 @@ where
716714
Err(err)
717715
}
718716

719-
pub(crate) fn poll_flush(&mut self, cx: &mut task::Context<'_>) -> Poll<io::Result<()>> {
717+
pub(crate) fn poll_flush(&mut self, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
720718
ready!(Pin::new(&mut self.io).poll_flush(cx))?;
721719
self.try_keep_alive(cx);
722720
trace!("flushed({}): {:?}", T::LOG, self.state);
723721
Poll::Ready(Ok(()))
724722
}
725723

726-
pub(crate) fn poll_shutdown(&mut self, cx: &mut task::Context<'_>) -> Poll<io::Result<()>> {
724+
pub(crate) fn poll_shutdown(&mut self, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
727725
match ready!(Pin::new(self.io.io_mut()).poll_shutdown(cx)) {
728726
Ok(()) => {
729727
trace!("shut down IO complete");
@@ -737,7 +735,7 @@ where
737735
}
738736

739737
/// If the read side can be cheaply drained, do so. Otherwise, close.
740-
pub(super) fn poll_drain_or_close_read(&mut self, cx: &mut task::Context<'_>) {
738+
pub(super) fn poll_drain_or_close_read(&mut self, cx: &mut Context<'_>) {
741739
if let Reading::Continue(ref decoder) = self.state.reading {
742740
// skip sending the 100-continue
743741
// just move forward to a read, in case a tiny body was included

0 commit comments

Comments
 (0)