feat(body): change Payload::Data to be a Buf

Closes #1508

BREAKING CHANGE: Each payload chunk must implement `Buf`, instead of
  just `AsRef<[u8]>`.
This commit is contained in:
Sean McArthur
2018-05-07 10:06:28 -07:00
parent dfa7e17960
commit a3be110a55
6 changed files with 34 additions and 30 deletions

View File

@@ -5,7 +5,6 @@ use http::HeaderMap;
use http::header::{CONNECTION, TRANSFER_ENCODING};
use ::body::Payload;
use ::proto::h1::Cursor;
mod client;
mod server;
@@ -74,11 +73,11 @@ where
let is_eos = self.stream.is_end_stream();
trace!(
"send body chunk: {} bytes, eos={}",
chunk.as_ref().len(),
chunk.remaining(),
is_eos,
);
let buf = SendBuf(Some(Cursor::new(chunk)));
let buf = SendBuf(Some(chunk));
self.body_tx.send_data(buf, is_eos)
.map_err(::Error::new_body_write)?;
@@ -104,9 +103,9 @@ where
}
}
struct SendBuf<B>(Option<Cursor<B>>);
struct SendBuf<B>(Option<B>);
impl<B: AsRef<[u8]>> Buf for SendBuf<B> {
impl<B: Buf> Buf for SendBuf<B> {
#[inline]
fn remaining(&self) -> usize {
self.0