self.content += l;
}
pub fn is_empty(&self) -> bool { self.content == 0 }
+ pub fn len(&self) -> usize { self.content }
}
impl FrameQueueBuf {
self.queue.push_(Cervine::Borrowed(&SLIP_END_SLICE));
}
pub fn is_empty(&self) -> bool { self.queue.is_empty() }
+ pub fn len(&self) -> usize { self.queue.len() }
}
impl<E> Extend<E> for FrameQueueBuf where E: Into<Box<[u8]>> {
fn chunk(&self) -> &[u8] { self.queue.chunk() }
fn advance(&mut self, cnt: usize) { self.queue.advance(cnt) }
}
+
+pin_project!{
+ pub struct BufBody<B:Buf> {
+ body: Option<B>,
+ }
+}
+impl<B:Buf> BufBody<B> {
+ pub fn new(body: B) -> Self { Self { body: Some(body ) } }
+}
+impl BufBody<FrameQueueBuf> {
+ pub fn display<S:Display>(s: S) -> Self {
+ let s = s.to_string().into_bytes();
+ let mut buf: FrameQueueBuf = default();
+ buf.push(s);
+ Self::new(buf)
+ }
+}
+
+impl<B:Buf> HttpBody for BufBody<B> {
+ type Error = Void;
+ type Data = B;
+ fn poll_data(self: Pin<&mut Self>, _: &mut std::task::Context<'_>)
+ -> Poll<Option<Result<B, Void>>> {
+ Poll::Ready(Ok(self.project().body.take()).transpose())
+ }
+ fn poll_trailers(self: Pin<&mut Self>, _: &mut std::task::Context<'_>)
+ -> Poll<Result<Option<hyper::HeaderMap<hyper::header::HeaderValue>>, Void>> {
+ Poll::Ready(Ok(None))
+ }
+}