Skip to main content

hyper_utils/http_body_util/
body_ext.rs

1use crate::http_body_util::{Frame, combinators};
2
3/// An extension trait for [`http_body::Body`] adding various combinators and adapters
4pub trait BodyExt: hyper::body::Body {
5    /// Returns a future that resolves to the next [`Frame`], if any.
6    ///
7    /// [`Frame`]: combinators::Frame
8    fn frame(&mut self) -> Frame<'_, Self>
9    where
10        Self: Unpin,
11    {
12        Frame(self)
13    }
14
15    /// Turn this body into [`Collected`] body which will collect all the DATA frames
16    /// and trailers.
17    fn collect(self) -> combinators::Collect<Self>
18    where
19        Self: Sized,
20    {
21        combinators::Collect {
22            body: self,
23            collected: Some(super::Collected::default()),
24        }
25    }
26}
27
28impl<T: ?Sized> BodyExt for T where T: hyper::body::Body {}