aws_smithy_http_server/
body.rs1#[doc(hidden)]
10pub use http_body::Body as HttpBody;
11
12pub use hyper::body::Body;
13
14use bytes::Bytes;
15
16use crate::error::{BoxError, Error};
17
18pub type BoxBody = http_body::combinators::UnsyncBoxBody<Bytes, Error>;
20
21pub fn boxed<B>(body: B) -> BoxBody
24where
25 B: http_body::Body<Data = Bytes> + Send + 'static,
26 B::Error: Into<BoxError>,
27{
28 try_downcast(body).unwrap_or_else(|body| body.map_err(Error::new).boxed_unsync())
29}
30
31#[doc(hidden)]
32pub(crate) fn try_downcast<T, K>(k: K) -> Result<T, K>
33where
34 T: 'static,
35 K: Send + 'static,
36{
37 let mut k = Some(k);
38 if let Some(k) = <dyn std::any::Any>::downcast_mut::<Option<T>>(&mut k) {
39 Ok(k.take().unwrap())
40 } else {
41 Err(k.unwrap())
42 }
43}
44
45pub(crate) fn empty() -> BoxBody {
46 boxed(http_body::Empty::new())
47}
48
49#[doc(hidden)]
52pub fn to_boxed<B>(body: B) -> BoxBody
53where
54 Body: From<B>,
55{
56 boxed(Body::from(body))
57}