Skip to main content

box_body

Function box_body 

Source
pub fn box_body<B>(body: B) -> BoxBody
where B: Body<Data = Bytes> + Send + 'static, B::Error: Into<Error>,
Available on crate feature http only.
Expand description

Erase a concrete HTTP body into a BoxBody.

This unifies several different body types behind a single Response<BoxBody> type, which is useful for handlers whose branches produce different bodies (streaming, full, empty, and so on). Any body whose data is bytes::Bytes and whose error converts into anyhow::Error, including the infallible EmptyBody and FullBody, can be boxed.

See BoxBody for a complete example.