1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-25 00:43:00 +01:00
actix-web/src/payload.rs

33 lines
743 B
Rust
Raw Normal View History

2019-02-07 22:39:15 +01:00
use bytes::Bytes;
use derive_more::From;
use futures::{Poll, Stream};
use h2::RecvStream;
use crate::error::PayloadError;
#[derive(From)]
pub enum Payload {
H1(crate::h1::Payload),
H2(crate::h2::Payload),
Dyn(Box<Stream<Item = Bytes, Error = PayloadError>>),
}
impl From<RecvStream> for Payload {
fn from(v: RecvStream) -> Self {
Payload::H2(crate::h2::Payload::new(v))
}
}
impl Stream for Payload {
type Item = Bytes;
type Error = PayloadError;
fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error> {
match self {
Payload::H1(ref mut pl) => pl.poll(),
Payload::H2(ref mut pl) => pl.poll(),
Payload::Dyn(ref mut pl) => pl.poll(),
}
}
}