Skip to content

Commit 7390f02

Browse files
committed
Revert "refactor(lib): Switch from pin-project to pin-project-lite"
This reverts commit 43412a9.
1 parent 48d4594 commit 7390f02

File tree

14 files changed

+255
-336
lines changed

14 files changed

+255
-336
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ httparse = "1.0"
3434
h2 = { version = "0.3", optional = true }
3535
itoa = "0.4.1"
3636
tracing = { version = "0.1", default-features = false, features = ["std"] }
37-
pin-project-lite = "0.2.4"
37+
pin-project = "1.0"
3838
tower-service = "0.3"
3939
tokio = { version = "1", features = ["sync"] }
4040
want = "0.3"

src/client/conn.rs

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ use std::time::Duration;
5656

5757
use bytes::Bytes;
5858
use futures_util::future::{self, Either, FutureExt as _};
59-
use pin_project_lite::pin_project;
59+
use pin_project::pin_project;
6060
use tokio::io::{AsyncRead, AsyncWrite};
6161
use tower_service::Service;
6262

@@ -75,23 +75,15 @@ use crate::{Body, Request, Response};
7575
#[cfg(feature = "http1")]
7676
type Http1Dispatcher<T, B, R> = proto::dispatch::Dispatcher<proto::dispatch::Client<B>, B, T, R>;
7777

78-
pin_project! {
79-
#[project = ProtoClientProj]
80-
enum ProtoClient<T, B>
81-
where
82-
B: HttpBody,
83-
{
84-
#[cfg(feature = "http1")]
85-
H1 {
86-
#[pin]
87-
h1: Http1Dispatcher<T, B, proto::h1::ClientTransaction>,
88-
},
89-
#[cfg(feature = "http2")]
90-
H2 {
91-
#[pin]
92-
h2: proto::h2::ClientTask<B>, _phantom: PhantomData<fn(T)>,
93-
},
94-
}
78+
#[pin_project(project = ProtoClientProj)]
79+
enum ProtoClient<T, B>
80+
where
81+
B: HttpBody,
82+
{
83+
#[cfg(feature = "http1")]
84+
H1(#[pin] Http1Dispatcher<T, B, proto::h1::ClientTransaction>),
85+
#[cfg(feature = "http2")]
86+
H2(#[pin] proto::h2::ClientTask<B>, PhantomData<fn(T)>),
9587
}
9688

9789
/// Returns a handshake future over some IO.
@@ -408,7 +400,7 @@ where
408400
pub fn into_parts(self) -> Parts<T> {
409401
match self.inner.expect("already upgraded") {
410402
#[cfg(feature = "http1")]
411-
ProtoClient::H1 { h1 } => {
403+
ProtoClient::H1(h1) => {
412404
let (io, read_buf, _) = h1.into_inner();
413405
Parts {
414406
io,
@@ -417,7 +409,7 @@ where
417409
}
418410
}
419411
#[cfg(feature = "http2")]
420-
ProtoClient::H2 { .. } => {
412+
ProtoClient::H2(..) => {
421413
panic!("http2 cannot into_inner");
422414
}
423415
}
@@ -437,9 +429,9 @@ where
437429
pub fn poll_without_shutdown(&mut self, cx: &mut task::Context<'_>) -> Poll<crate::Result<()>> {
438430
match *self.inner.as_mut().expect("already upgraded") {
439431
#[cfg(feature = "http1")]
440-
ProtoClient::H1 { ref mut h1 } => h1.poll_without_shutdown(cx),
432+
ProtoClient::H1(ref mut h1) => h1.poll_without_shutdown(cx),
441433
#[cfg(feature = "http2")]
442-
ProtoClient::H2 { ref mut h2, .. } => Pin::new(h2).poll(cx).map_ok(|_| ()),
434+
ProtoClient::H2(ref mut h2, _) => Pin::new(h2).poll(cx).map_ok(|_| ()),
443435
}
444436
}
445437

@@ -468,7 +460,7 @@ where
468460
proto::Dispatched::Shutdown => Poll::Ready(Ok(())),
469461
#[cfg(feature = "http1")]
470462
proto::Dispatched::Upgrade(pending) => match self.inner.take() {
471-
Some(ProtoClient::H1 { h1 }) => {
463+
Some(ProtoClient::H1(h1)) => {
472464
let (io, buf, _) = h1.into_inner();
473465
pending.fulfill(Upgraded::new(io, buf));
474466
Poll::Ready(Ok(()))
@@ -715,17 +707,14 @@ impl Builder {
715707
}
716708
let cd = proto::h1::dispatch::Client::new(rx);
717709
let dispatch = proto::h1::Dispatcher::new(cd, conn);
718-
ProtoClient::H1 { h1: dispatch }
710+
ProtoClient::H1(dispatch)
719711
}
720712
#[cfg(feature = "http2")]
721713
Proto::Http2 => {
722714
let h2 =
723715
proto::h2::client::handshake(io, rx, &opts.h2_builder, opts.exec.clone())
724716
.await?;
725-
ProtoClient::H2 {
726-
h2,
727-
_phantom: PhantomData,
728-
}
717+
ProtoClient::H2(h2, PhantomData)
729718
}
730719
};
731720

@@ -779,9 +768,9 @@ where
779768
fn poll(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output> {
780769
match self.project() {
781770
#[cfg(feature = "http1")]
782-
ProtoClientProj::H1 { h1 } => h1.poll(cx),
771+
ProtoClientProj::H1(c) => c.poll(cx),
783772
#[cfg(feature = "http2")]
784-
ProtoClientProj::H2 { h2, .. } => h2.poll(cx),
773+
ProtoClientProj::H2(c, _) => c.poll(cx),
785774
}
786775
}
787776
}

src/client/connect/http.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::time::Duration;
1111

1212
use futures_util::future::Either;
1313
use http::uri::{Scheme, Uri};
14-
use pin_project_lite::pin_project;
14+
use pin_project::pin_project;
1515
use tokio::net::{TcpSocket, TcpStream};
1616
use tokio::time::Sleep;
1717

@@ -373,19 +373,18 @@ impl HttpInfo {
373373
}
374374
}
375375

376-
pin_project! {
377-
// Not publicly exported (so missing_docs doesn't trigger).
378-
//
379-
// We return this `Future` instead of the `Pin<Box<dyn Future>>` directly
380-
// so that users don't rely on it fitting in a `Pin<Box<dyn Future>>` slot
381-
// (and thus we can change the type in the future).
382-
#[must_use = "futures do nothing unless polled"]
383-
#[allow(missing_debug_implementations)]
384-
pub struct HttpConnecting<R> {
385-
#[pin]
386-
fut: BoxConnecting,
387-
_marker: PhantomData<R>,
388-
}
376+
// Not publicly exported (so missing_docs doesn't trigger).
377+
//
378+
// We return this `Future` instead of the `Pin<Box<dyn Future>>` directly
379+
// so that users don't rely on it fitting in a `Pin<Box<dyn Future>>` slot
380+
// (and thus we can change the type in the future).
381+
#[must_use = "futures do nothing unless polled"]
382+
#[pin_project]
383+
#[allow(missing_debug_implementations)]
384+
pub struct HttpConnecting<R> {
385+
#[pin]
386+
fut: BoxConnecting,
387+
_marker: PhantomData<R>,
389388
}
390389

391390
type ConnectResult = Result<TcpStream, ConnectError>;

src/client/pool.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use futures_channel::oneshot;
1111
use tokio::time::{Duration, Instant, Interval};
1212

1313
use super::client::Ver;
14-
use crate::common::{exec::Exec, task, Future, Pin, Poll, Unpin};
14+
use crate::common::{task, exec::Exec, Future, Pin, Poll, Unpin};
1515

1616
// FIXME: allow() required due to `impl Trait` leaking types to this lint
1717
#[allow(missing_debug_implementations)]
@@ -714,17 +714,16 @@ impl Expiration {
714714
}
715715

716716
#[cfg(feature = "runtime")]
717-
pin_project_lite::pin_project! {
718-
struct IdleTask<T> {
719-
#[pin]
720-
interval: Interval,
721-
pool: WeakOpt<Mutex<PoolInner<T>>>,
722-
// This allows the IdleTask to be notified as soon as the entire
723-
// Pool is fully dropped, and shutdown. This channel is never sent on,
724-
// but Err(Canceled) will be received when the Pool is dropped.
725-
#[pin]
726-
pool_drop_notifier: oneshot::Receiver<crate::common::Never>,
727-
}
717+
#[pin_project::pin_project]
718+
struct IdleTask<T> {
719+
#[pin]
720+
interval: Interval,
721+
pool: WeakOpt<Mutex<PoolInner<T>>>,
722+
// This allows the IdleTask to be notified as soon as the entire
723+
// Pool is fully dropped, and shutdown. This channel is never sent on,
724+
// but Err(Canceled) will be received when the Pool is dropped.
725+
#[pin]
726+
pool_drop_notifier: oneshot::Receiver<crate::common::Never>,
728727
}
729728

730729
#[cfg(feature = "runtime")]
@@ -777,7 +776,7 @@ mod tests {
777776
use std::time::Duration;
778777

779778
use super::{Connecting, Key, Pool, Poolable, Reservation, WeakOpt};
780-
use crate::common::{exec::Exec, task, Future, Pin};
779+
use crate::common::{task, exec::Exec, Future, Pin};
781780

782781
/// Test unique reservations.
783782
#[derive(Debug, PartialEq, Eq)]

src/common/drain.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::mem;
22

3-
use pin_project_lite::pin_project;
3+
use pin_project::pin_project;
44
use tokio::sync::watch;
55

66
use super::{task, Future, Pin, Poll};
@@ -21,15 +21,14 @@ pub(crate) struct Watch {
2121
rx: watch::Receiver<()>,
2222
}
2323

24-
pin_project! {
25-
#[allow(missing_debug_implementations)]
26-
pub struct Watching<F, FN> {
27-
#[pin]
28-
future: F,
29-
state: State<FN>,
30-
watch: Pin<Box<dyn Future<Output = ()> + Send + Sync>>,
31-
_rx: watch::Receiver<()>,
32-
}
24+
#[allow(missing_debug_implementations)]
25+
#[pin_project]
26+
pub struct Watching<F, FN> {
27+
#[pin]
28+
future: F,
29+
state: State<FN>,
30+
watch: Pin<Box<dyn Future<Output = ()> + Send + Sync>>,
31+
_rx: watch::Receiver<()>,
3332
}
3433

3534
enum State<F> {

src/proto/h1/dispatch.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,10 @@ cfg_server! {
4444
}
4545

4646
cfg_client! {
47-
pin_project_lite::pin_project! {
48-
pub(crate) struct Client<B> {
49-
callback: Option<crate::client::dispatch::Callback<Request<B>, http::Response<Body>>>,
50-
#[pin]
51-
rx: ClientRx<B>,
52-
rx_closed: bool,
53-
}
47+
pub(crate) struct Client<B> {
48+
callback: Option<crate::client::dispatch::Callback<Request<B>, http::Response<Body>>>,
49+
rx: ClientRx<B>,
50+
rx_closed: bool,
5451
}
5552

5653
type ClientRx<B> = crate::client::dispatch::Receiver<Request<B>, http::Response<Body>>;

src/proto/h2/mod.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use http::header::{
55
TRANSFER_ENCODING, UPGRADE,
66
};
77
use http::HeaderMap;
8-
use pin_project_lite::pin_project;
8+
use pin_project::pin_project;
99
use std::error::Error as StdError;
1010
use std::io::IoSlice;
1111

@@ -94,16 +94,15 @@ fn decode_content_length(headers: &HeaderMap) -> DecodedLength {
9494

9595
// body adapters used by both Client and Server
9696

97-
pin_project! {
98-
struct PipeToSendStream<S>
99-
where
100-
S: HttpBody,
101-
{
102-
body_tx: SendStream<SendBuf<S::Data>>,
103-
data_done: bool,
104-
#[pin]
105-
stream: S,
106-
}
97+
#[pin_project]
98+
struct PipeToSendStream<S>
99+
where
100+
S: HttpBody,
101+
{
102+
body_tx: SendStream<SendBuf<S::Data>>,
103+
data_done: bool,
104+
#[pin]
105+
stream: S,
107106
}
108107

109108
impl<S> PipeToSendStream<S>

0 commit comments

Comments
 (0)