Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions http-body/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,31 @@ impl Body for String {
}
}

impl Body for Vec<u8> {
type Data = Bytes;
type Error = Infallible;

fn poll_frame(
mut self: Pin<&mut Self>,
_cx: &mut Context<'_>,
) -> Poll<Option<Result<Frame<Self::Data>, Self::Error>>> {
if !self.is_empty() {
let s = std::mem::take(&mut *self);
Poll::Ready(Some(Ok(Frame::data(Bytes::from(s)))))
} else {
Poll::Ready(None)
}
}

fn is_end_stream(&self) -> bool {
self.is_empty()
}

fn size_hint(&self) -> SizeHint {
SizeHint::with_exact(self.len() as u64)
}
}

#[cfg(test)]
fn _assert_bounds() {
fn can_be_trait_object(_: &dyn Body<Data = std::io::Cursor<Vec<u8>>, Error = std::io::Error>) {}
Expand Down