From e544fe1c395ff3304ba679413bfb1af1b1da6fa6 Mon Sep 17 00:00:00 2001 From: David Pedersen Date: Thu, 22 Jul 2021 11:14:55 +0200 Subject: [PATCH] More flexible generic responses --- src/response.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/response.rs b/src/response.rs index 6acf3630..f7157ab6 100644 --- a/src/response.rs +++ b/src/response.rs @@ -137,22 +137,21 @@ impl IntoResponse for StatusCode { impl IntoResponse for (StatusCode, T) where - T: Into, + T: IntoResponse, { fn into_response(self) -> Response { - Response::builder() - .status(self.0) - .body(self.1.into()) - .unwrap() + let mut res = self.1.into_response(); + *res.status_mut() = self.0; + res } } impl IntoResponse for (HeaderMap, T) where - T: Into, + T: IntoResponse, { fn into_response(self) -> Response { - let mut res = Response::new(self.1.into()); + let mut res = self.1.into_response(); *res.headers_mut() = self.0; res } @@ -160,10 +159,10 @@ where impl IntoResponse for (StatusCode, HeaderMap, T) where - T: Into, + T: IntoResponse, { fn into_response(self) -> Response { - let mut res = Response::new(self.2.into()); + let mut res = self.2.into_response(); *res.status_mut() = self.0; *res.headers_mut() = self.1; res