pub type BoxBody = UnsyncBoxBody<Bytes, Error>;Available on crate feature
http only.Expand description
A type-erased HTTP body.
This is a convenience alias for http_body_util::combinators::UnsyncBoxBody
carrying bytes::Bytes data and anyhow::Error errors.
It is useful when a handler produces different concrete body types on
different code paths, for example, a streaming body on one branch and an
EmptyBody on another. Because those bodies have different types, they
cannot be returned from the same match or if directly. Erasing each one
to a BoxBody with box_body gives every branch the single, shared type
Response<BoxBody>.
§Examples
use spin_sdk::http::{box_body, BoxBody, EmptyBody, FullBody, Response};
let response: Response<BoxBody> = if found() {
Response::new(box_body(FullBody::new(bytes::Bytes::from("hello"))))
} else {
Response::builder()
.status(404)
.body(box_body(EmptyBody::new()))
.unwrap()
};Aliased Type§
pub struct BoxBody { /* private fields */ }