1use bytes::Bytes;
6use http_body_util::BodyExt;
7
8use crate::BoxError;
9
10pub type BoxBody = http_body_util::combinators::UnsyncBoxBody<Bytes, BoxError>;
11
12pub fn boxed<B>(body: B) -> BoxBody
13where
14 B: http_body::Body<Data = Bytes> + Send + 'static,
15 B::Error: Into<BoxError>,
16{
17 try_downcast(body).unwrap_or_else(|body| body.map_err(Into::into).boxed_unsync())
18}
19
20pub(crate) fn try_downcast<T, K>(k: K) -> Result<T, K>
21where
22 T: 'static,
23 K: Send + 'static,
24{
25 let mut k = Some(k);
26 if let Some(k) = <dyn std::any::Any>::downcast_mut::<Option<T>>(&mut k) {
27 Ok(k.take().unwrap())
28 } else {
29 Err(k.unwrap())
30 }
31}