#![doc(html_root_url = "https://docs.rs/http-body/0.1.0")]
#![deny(missing_debug_implementations, missing_docs, unreachable_pub)]
#![cfg_attr(test, deny(warnings))]
extern crate bytes;
extern crate futures;
extern crate http;
extern crate tokio_buf;
use bytes::Buf;
use futures::{Async, Poll};
use http::HeaderMap;
use tokio_buf::{BufStream, SizeHint};
pub trait Body {
type Data: Buf;
type Error;
fn poll_data(&mut self) -> Poll<Option<Self::Data>, Self::Error>;
fn size_hint(&self) -> SizeHint {
SizeHint::default()
}
fn poll_trailers(&mut self) -> Poll<Option<HeaderMap>, Self::Error>;
fn is_end_stream(&self) -> bool {
false
}
}
impl<T: BufStream> Body for T {
type Data = T::Item;
type Error = T::Error;
fn poll_data(&mut self) -> Poll<Option<Self::Data>, Self::Error> {
BufStream::poll_buf(self)
}
fn size_hint(&self) -> SizeHint {
BufStream::size_hint(self)
}
fn poll_trailers(&mut self) -> Poll<Option<HeaderMap>, Self::Error> {
Ok(Async::Ready(None))
}
fn is_end_stream(&self) -> bool {
let size_hint = self.size_hint();
size_hint
.upper()
.map(|upper| upper == 0 && upper == size_hint.lower())
.unwrap_or(false)
}
}