remove unneed type bound.

This commit is contained in:
fakeshadow 2021-05-13 14:53:44 +08:00
parent 94fa95d969
commit 49d2e3f02d
2 changed files with 67 additions and 74 deletions

View File

@ -1,5 +1,12 @@
use std::task::{Context, Poll};
use std::{cmp, future::Future, marker::PhantomData, net, pin::Pin, rc::Rc};
use std::{
cmp,
future::Future,
marker::PhantomData,
net,
pin::Pin,
rc::Rc,
task::{Context, Poll},
};
use actix_codec::{AsyncRead, AsyncWrite};
use actix_service::Service;
@ -9,6 +16,7 @@ use futures_core::ready;
use h2::server::{Connection, SendResponse};
use http::header::{HeaderValue, CONNECTION, CONTENT_LENGTH, DATE, TRANSFER_ENCODING};
use log::{error, trace};
use pin_project_lite::pin_project;
use crate::body::{BodySize, MessageBody};
use crate::config::ServiceConfig;
@ -22,14 +30,9 @@ use crate::OnConnectData;
const CHUNK_SIZE: usize = 16_384;
pin_project! {
/// Dispatcher for HTTP/2 protocol.
#[pin_project::pin_project]
pub struct Dispatcher<T, S, B, X, U>
where
T: AsyncRead + AsyncWrite + Unpin,
S: Service<Request>,
B: MessageBody,
{
pub struct Dispatcher<T, S, B, X, U> {
flow: Rc<HttpFlow<S, X, U>>,
connection: Connection<T, Bytes>,
on_connect_data: OnConnectData,
@ -37,15 +40,9 @@ where
peer_addr: Option<net::SocketAddr>,
_phantom: PhantomData<B>,
}
}
impl<T, S, B, X, U> Dispatcher<T, S, B, X, U>
where
T: AsyncRead + AsyncWrite + Unpin,
S: Service<Request>,
S::Error: Into<Error>,
S::Response: Into<Response<B>>,
B: MessageBody,
{
impl<T, S, B, X, U> Dispatcher<T, S, B, X, U> {
pub(crate) fn new(
flow: Rc<HttpFlow<S, X, U>>,
connection: Connection<T, Bytes>,
@ -53,7 +50,7 @@ where
config: ServiceConfig,
peer_addr: Option<net::SocketAddr>,
) -> Self {
Dispatcher {
Self {
flow,
config,
peer_addr,
@ -82,13 +79,9 @@ where
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let this = self.get_mut();
loop {
match ready!(Pin::new(&mut this.connection).poll_accept(cx)) {
None => return Poll::Ready(Ok(())),
Some(Err(err)) => return Poll::Ready(Err(err.into())),
Some(Ok((req, tx))) => {
while let Some((req, tx)) =
ready!(Pin::new(&mut this.connection).poll_accept(cx)).transpose()?
{
let (parts, body) = req.into_parts();
let pl = crate::h2::Payload::new(body);
let pl = Payload::<crate::payload::PayloadStream>::H2(pl);
@ -136,8 +129,8 @@ where
}
});
}
}
}
Poll::Ready(Ok(()))
}
}

View File

@ -84,7 +84,7 @@ impl<B> Response<B> {
pub fn with_body(status: StatusCode, body: B) -> Response<B> {
Response {
head: BoxedResponseHead::new(status),
body: body,
body,
}
}