refactor(lib): Switch from pin-project to pin-project-lite
This commit is contained in:
committed by
Sean McArthur
parent
9dff00425d
commit
43412a950f
@@ -56,7 +56,7 @@ use std::time::Duration;
|
||||
|
||||
use bytes::Bytes;
|
||||
use futures_util::future::{self, Either, FutureExt as _};
|
||||
use pin_project::pin_project;
|
||||
use pin_project_lite::pin_project;
|
||||
use tokio::io::{AsyncRead, AsyncWrite};
|
||||
use tower_service::Service;
|
||||
|
||||
@@ -75,15 +75,23 @@ use crate::{Body, Request, Response};
|
||||
#[cfg(feature = "http1")]
|
||||
type Http1Dispatcher<T, B, R> = proto::dispatch::Dispatcher<proto::dispatch::Client<B>, B, T, R>;
|
||||
|
||||
#[pin_project(project = ProtoClientProj)]
|
||||
enum ProtoClient<T, B>
|
||||
where
|
||||
B: HttpBody,
|
||||
{
|
||||
#[cfg(feature = "http1")]
|
||||
H1(#[pin] Http1Dispatcher<T, B, proto::h1::ClientTransaction>),
|
||||
#[cfg(feature = "http2")]
|
||||
H2(#[pin] proto::h2::ClientTask<B>, PhantomData<fn(T)>),
|
||||
pin_project! {
|
||||
#[project = ProtoClientProj]
|
||||
enum ProtoClient<T, B>
|
||||
where
|
||||
B: HttpBody,
|
||||
{
|
||||
#[cfg(feature = "http1")]
|
||||
H1 {
|
||||
#[pin]
|
||||
h1: Http1Dispatcher<T, B, proto::h1::ClientTransaction>,
|
||||
},
|
||||
#[cfg(feature = "http2")]
|
||||
H2 {
|
||||
#[pin]
|
||||
h2: proto::h2::ClientTask<B>, _phantom: PhantomData<fn(T)>,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a handshake future over some IO.
|
||||
@@ -400,7 +408,7 @@ where
|
||||
pub fn into_parts(self) -> Parts<T> {
|
||||
match self.inner.expect("already upgraded") {
|
||||
#[cfg(feature = "http1")]
|
||||
ProtoClient::H1(h1) => {
|
||||
ProtoClient::H1 { h1 } => {
|
||||
let (io, read_buf, _) = h1.into_inner();
|
||||
Parts {
|
||||
io,
|
||||
@@ -409,7 +417,7 @@ where
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "http2")]
|
||||
ProtoClient::H2(..) => {
|
||||
ProtoClient::H2 { .. } => {
|
||||
panic!("http2 cannot into_inner");
|
||||
}
|
||||
}
|
||||
@@ -429,9 +437,9 @@ where
|
||||
pub fn poll_without_shutdown(&mut self, cx: &mut task::Context<'_>) -> Poll<crate::Result<()>> {
|
||||
match *self.inner.as_mut().expect("already upgraded") {
|
||||
#[cfg(feature = "http1")]
|
||||
ProtoClient::H1(ref mut h1) => h1.poll_without_shutdown(cx),
|
||||
ProtoClient::H1 { ref mut h1 } => h1.poll_without_shutdown(cx),
|
||||
#[cfg(feature = "http2")]
|
||||
ProtoClient::H2(ref mut h2, _) => Pin::new(h2).poll(cx).map_ok(|_| ()),
|
||||
ProtoClient::H2 { ref mut h2, .. } => Pin::new(h2).poll(cx).map_ok(|_| ()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -460,7 +468,7 @@ where
|
||||
proto::Dispatched::Shutdown => Poll::Ready(Ok(())),
|
||||
#[cfg(feature = "http1")]
|
||||
proto::Dispatched::Upgrade(pending) => match self.inner.take() {
|
||||
Some(ProtoClient::H1(h1)) => {
|
||||
Some(ProtoClient::H1 { h1 }) => {
|
||||
let (io, buf, _) = h1.into_inner();
|
||||
pending.fulfill(Upgraded::new(io, buf));
|
||||
Poll::Ready(Ok(()))
|
||||
@@ -707,14 +715,17 @@ impl Builder {
|
||||
}
|
||||
let cd = proto::h1::dispatch::Client::new(rx);
|
||||
let dispatch = proto::h1::Dispatcher::new(cd, conn);
|
||||
ProtoClient::H1(dispatch)
|
||||
ProtoClient::H1 { h1: dispatch }
|
||||
}
|
||||
#[cfg(feature = "http2")]
|
||||
Proto::Http2 => {
|
||||
let h2 =
|
||||
proto::h2::client::handshake(io, rx, &opts.h2_builder, opts.exec.clone())
|
||||
.await?;
|
||||
ProtoClient::H2(h2, PhantomData)
|
||||
ProtoClient::H2 {
|
||||
h2,
|
||||
_phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -768,9 +779,9 @@ where
|
||||
fn poll(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output> {
|
||||
match self.project() {
|
||||
#[cfg(feature = "http1")]
|
||||
ProtoClientProj::H1(c) => c.poll(cx),
|
||||
ProtoClientProj::H1 { h1 } => h1.poll(cx),
|
||||
#[cfg(feature = "http2")]
|
||||
ProtoClientProj::H2(c, _) => c.poll(cx),
|
||||
ProtoClientProj::H2 { h2, .. } => h2.poll(cx),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user