refactor(body): use HttpBody with extra bounds instead of Payload trait

This commit is contained in:
Dirkjan Ochtman
2020-04-19 21:59:52 +02:00
committed by Sean McArthur
parent 203621e3be
commit aac0e2dd57
20 changed files with 142 additions and 243 deletions

View File

@@ -9,7 +9,7 @@ use pin_project::{pin_project, project};
use tokio::io::{AsyncRead, AsyncWrite};
use super::{decode_content_length, ping, PipeToSendStream, SendBuf};
use crate::body::Payload;
use crate::body::HttpBody;
use crate::common::exec::H2Exec;
use crate::common::{task, Future, Pin, Poll};
use crate::headers;
@@ -58,7 +58,7 @@ impl Default for Config {
pub(crate) struct Server<T, S, B, E>
where
S: HttpService<Body>,
B: Payload,
B: HttpBody,
{
exec: E,
service: S,
@@ -67,7 +67,7 @@ where
enum State<T, B>
where
B: Payload,
B: HttpBody,
{
Handshaking {
ping_config: ping::Config,
@@ -79,7 +79,7 @@ where
struct Serving<T, B>
where
B: Payload,
B: HttpBody,
{
ping: Option<(ping::Recorder, ping::Ponger)>,
conn: Connection<T, SendBuf<B::Data>>,
@@ -91,7 +91,7 @@ where
T: AsyncRead + AsyncWrite + Unpin,
S: HttpService<Body, ResBody = B>,
S::Error: Into<Box<dyn StdError + Send + Sync>>,
B: Payload,
B: HttpBody + 'static,
E: H2Exec<S::Future, B>,
{
pub(crate) fn new(io: T, service: S, config: &Config, exec: E) -> Server<T, S, B, E> {
@@ -157,7 +157,7 @@ where
T: AsyncRead + AsyncWrite + Unpin,
S: HttpService<Body, ResBody = B>,
S::Error: Into<Box<dyn StdError + Send + Sync>>,
B: Payload,
B: HttpBody + 'static,
E: H2Exec<S::Future, B>,
{
type Output = crate::Result<Dispatched>;
@@ -201,7 +201,7 @@ where
impl<T, B> Serving<T, B>
where
T: AsyncRead + AsyncWrite + Unpin,
B: Payload,
B: HttpBody + 'static,
{
fn poll_server<S, E>(
&mut self,
@@ -315,7 +315,7 @@ where
#[pin_project]
pub struct H2Stream<F, B>
where
B: Payload,
B: HttpBody,
{
reply: SendResponse<SendBuf<B::Data>>,
#[pin]
@@ -325,7 +325,7 @@ where
#[pin_project]
enum H2StreamState<F, B>
where
B: Payload,
B: HttpBody,
{
Service(#[pin] F),
Body(#[pin] PipeToSendStream<B>),
@@ -333,7 +333,7 @@ where
impl<F, B> H2Stream<F, B>
where
B: Payload,
B: HttpBody,
{
fn new(fut: F, respond: SendResponse<SendBuf<B::Data>>) -> H2Stream<F, B> {
H2Stream {
@@ -359,7 +359,8 @@ macro_rules! reply {
impl<F, B, E> H2Stream<F, B>
where
F: Future<Output = Result<Response<B>, E>>,
B: Payload,
B: HttpBody,
B::Error: Into<Box<dyn StdError + Send + Sync>>,
E: Into<Box<dyn StdError + Send + Sync>>,
{
#[project]
@@ -424,7 +425,8 @@ where
impl<F, B, E> Future for H2Stream<F, B>
where
F: Future<Output = Result<Response<B>, E>>,
B: Payload,
B: HttpBody,
B::Error: Into<Box<dyn StdError + Send + Sync>>,
E: Into<Box<dyn StdError + Send + Sync>>,
{
type Output = ();