use bytes::Bytes; use futures::{Async, Poll, Stream}; use h2::RecvStream; use crate::error::PayloadError; /// Type represent boxed payload pub type PayloadStream = Box>; /// Type represent streaming payload pub enum Payload { None, H1(crate::h1::Payload), H2(crate::h2::Payload), Stream(S), } impl From for Payload { fn from(v: crate::h1::Payload) -> Self { Payload::H1(v) } } impl From for Payload { fn from(v: crate::h2::Payload) -> Self { Payload::H2(v) } } impl From for Payload { fn from(v: RecvStream) -> Self { Payload::H2(crate::h2::Payload::new(v)) } } impl From for Payload { fn from(pl: PayloadStream) -> Self { Payload::Stream(pl) } } impl Stream for Payload where S: Stream, { type Item = Bytes; type Error = PayloadError; fn poll(&mut self) -> Poll, Self::Error> { match self { Payload::None => Ok(Async::Ready(None)), Payload::H1(ref mut pl) => pl.poll(), Payload::H2(ref mut pl) => pl.poll(), Payload::Stream(ref mut pl) => pl.poll(), } } }