refactor(lib): Switch from pin-project to pin-project-lite (#2566)
Note the practical affects of this change: - Dependency count with --features full dropped from 65 to 55. - Time to compile after a clean dropped from 48s to 35s (on a pretty underpowered VM). Closes #2388
This commit is contained in:
@@ -7,7 +7,7 @@ use bytes::Bytes;
|
||||
use h2::server::{Connection, Handshake, SendResponse};
|
||||
use h2::{Reason, RecvStream};
|
||||
use http::{Method, Request};
|
||||
use pin_project::pin_project;
|
||||
use pin_project_lite::pin_project;
|
||||
use tokio::io::{AsyncRead, AsyncWrite};
|
||||
|
||||
use super::{ping, PipeToSendStream, SendBuf};
|
||||
@@ -62,15 +62,16 @@ impl Default for Config {
|
||||
}
|
||||
}
|
||||
|
||||
#[pin_project]
|
||||
pub(crate) struct Server<T, S, B, E>
|
||||
where
|
||||
S: HttpService<Body>,
|
||||
B: HttpBody,
|
||||
{
|
||||
exec: E,
|
||||
service: S,
|
||||
state: State<T, B>,
|
||||
pin_project! {
|
||||
pub(crate) struct Server<T, S, B, E>
|
||||
where
|
||||
S: HttpService<Body>,
|
||||
B: HttpBody,
|
||||
{
|
||||
exec: E,
|
||||
service: S,
|
||||
state: State<T, B>,
|
||||
}
|
||||
}
|
||||
|
||||
enum State<T, B>
|
||||
@@ -348,24 +349,34 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(missing_debug_implementations)]
|
||||
#[pin_project]
|
||||
pub struct H2Stream<F, B>
|
||||
where
|
||||
B: HttpBody,
|
||||
{
|
||||
reply: SendResponse<SendBuf<B::Data>>,
|
||||
#[pin]
|
||||
state: H2StreamState<F, B>,
|
||||
pin_project! {
|
||||
#[allow(missing_debug_implementations)]
|
||||
pub struct H2Stream<F, B>
|
||||
where
|
||||
B: HttpBody,
|
||||
{
|
||||
reply: SendResponse<SendBuf<B::Data>>,
|
||||
#[pin]
|
||||
state: H2StreamState<F, B>,
|
||||
}
|
||||
}
|
||||
|
||||
#[pin_project(project = H2StreamStateProj)]
|
||||
enum H2StreamState<F, B>
|
||||
where
|
||||
B: HttpBody,
|
||||
{
|
||||
Service(#[pin] F, Option<ConnectParts>),
|
||||
Body(#[pin] PipeToSendStream<B>),
|
||||
pin_project! {
|
||||
#[project = H2StreamStateProj]
|
||||
enum H2StreamState<F, B>
|
||||
where
|
||||
B: HttpBody,
|
||||
{
|
||||
Service {
|
||||
#[pin]
|
||||
fut: F,
|
||||
connect_parts: Option<ConnectParts>,
|
||||
},
|
||||
Body {
|
||||
#[pin]
|
||||
pipe: PipeToSendStream<B>,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
struct ConnectParts {
|
||||
@@ -385,7 +396,7 @@ where
|
||||
) -> H2Stream<F, B> {
|
||||
H2Stream {
|
||||
reply: respond,
|
||||
state: H2StreamState::Service(fut, connect_parts),
|
||||
state: H2StreamState::Service { fut, connect_parts },
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -415,7 +426,10 @@ where
|
||||
let mut me = self.project();
|
||||
loop {
|
||||
let next = match me.state.as_mut().project() {
|
||||
H2StreamStateProj::Service(h, connect_parts) => {
|
||||
H2StreamStateProj::Service {
|
||||
fut: h,
|
||||
connect_parts,
|
||||
} => {
|
||||
let res = match h.poll(cx) {
|
||||
Poll::Ready(Ok(r)) => r,
|
||||
Poll::Pending => {
|
||||
@@ -476,13 +490,15 @@ where
|
||||
|
||||
if !body.is_end_stream() {
|
||||
let body_tx = reply!(me, res, false);
|
||||
H2StreamState::Body(PipeToSendStream::new(body, body_tx))
|
||||
H2StreamState::Body {
|
||||
pipe: PipeToSendStream::new(body, body_tx),
|
||||
}
|
||||
} else {
|
||||
reply!(me, res, true);
|
||||
return Poll::Ready(Ok(()));
|
||||
}
|
||||
}
|
||||
H2StreamStateProj::Body(pipe) => {
|
||||
H2StreamStateProj::Body { pipe } => {
|
||||
return pipe.poll(cx);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user