From 1c8f09268bb610e1e6a375578458110cab84b3a2 Mon Sep 17 00:00:00 2001 From: David Pedersen Date: Thu, 3 Mar 2022 08:07:00 +0100 Subject: [PATCH] Implement `IntoResponseParts` for more tuples (#817) --- axum-core/src/response/into_response_parts.rs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/axum-core/src/response/into_response_parts.rs b/axum-core/src/response/into_response_parts.rs index bbe603ac..6022ea57 100644 --- a/axum-core/src/response/into_response_parts.rs +++ b/axum-core/src/response/into_response_parts.rs @@ -144,3 +144,32 @@ where } } } + +macro_rules! impl_into_response_parts { + ( $($ty:ident),* $(,)? ) => { + #[allow(non_snake_case)] + impl<$($ty,)*> IntoResponseParts for ($($ty,)*) + where + $( $ty: IntoResponseParts, )* + { + type Error = Response; + + fn into_response_parts(self, res: ResponseParts) -> Result { + let ($($ty,)*) = self; + + $( + let res = match $ty.into_response_parts(res) { + Ok(res) => res, + Err(err) => { + return Err(err.into_response()); + } + }; + )* + + Ok(res) + } + } + } +} + +all_the_tuples!(impl_into_response_parts);