diff options
Diffstat (limited to 'src/hyper_body.rs')
-rw-r--r-- | src/hyper_body.rs | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/hyper_body.rs b/src/hyper_body.rs index 50efdc3..7400633 100644 --- a/src/hyper_body.rs +++ b/src/hyper_body.rs @@ -15,17 +15,22 @@ impl EmptyBuilder<hyper::Body> for Builder { /// Adds deserialization methods to `hyper::Body`. pub trait SputnikBody { /// Parses a `application/x-www-form-urlencoded` request body into a given struct. - fn into_form<T: DeserializeOwned>(self) -> Pin<Box<dyn Future<Output=Result<T, FormError>> + Send + Sync>>; + fn into_form<T: DeserializeOwned>( + self, + ) -> Pin<Box<dyn Future<Output = Result<T, FormError>> + Send + Sync>>; /// Attempts to deserialize the request body as JSON. #[cfg(feature = "hyper_body_json")] #[cfg_attr(docsrs, doc(cfg(feature = "hyper_body_json")))] - fn into_json<T: DeserializeOwned>(self) -> Pin<Box<dyn Future<Output=Result<T, JsonError>> + Send + Sync>>; + fn into_json<T: DeserializeOwned>( + self, + ) -> Pin<Box<dyn Future<Output = Result<T, JsonError>> + Send + Sync>>; } impl SputnikBody for hyper::Body { - - fn into_form<T: DeserializeOwned>(self) -> Pin<Box<dyn Future<Output=Result<T, FormError>> + Send + Sync>> { + fn into_form<T: DeserializeOwned>( + self, + ) -> Pin<Box<dyn Future<Output = Result<T, FormError>> + Send + Sync>> { Box::pin(async move { let full_body = hyper::body::to_bytes(self).await.map_err(BodyError)?; Ok(serde_urlencoded::from_bytes::<T>(&full_body)?) @@ -34,7 +39,9 @@ impl SputnikBody for hyper::Body { #[cfg(feature = "hyper_body_json")] #[cfg_attr(docsrs, doc(cfg(feature = "hyper_body_json")))] - fn into_json<T: DeserializeOwned>(self) -> Pin<Box<dyn Future<Output=Result<T, JsonError>> + Send + Sync>> { + fn into_json<T: DeserializeOwned>( + self, + ) -> Pin<Box<dyn Future<Output = Result<T, JsonError>> + Send + Sync>> { Box::pin(async move { let full_body = hyper::body::to_bytes(self).await.map_err(BodyError)?; Ok(serde_json::from_slice::<T>(&full_body)?) @@ -64,4 +71,4 @@ pub enum JsonError { #[error("json deserialize error: {0}")] Deserialize(#[from] serde_json::Error), -}
\ No newline at end of file +} |