From b3e3f42e2467b079f2ce7660a64273bb9b887a03 Mon Sep 17 00:00:00 2001 From: David Pedersen Date: Thu, 3 Aug 2023 20:15:06 +0200 Subject: [PATCH] Implement `IntoResponse` for `(R,) where R: IntoResponse` (#2143) --- axum-core/src/response/into_response.rs | 10 ++++++++++ .../tests/debug_handler/fail/wrong_return_type.stderr | 2 +- axum/CHANGELOG.md | 4 +++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/axum-core/src/response/into_response.rs b/axum-core/src/response/into_response.rs index 898252a2e3..d1c67e5cf0 100644 --- a/axum-core/src/response/into_response.rs +++ b/axum-core/src/response/into_response.rs @@ -449,6 +449,16 @@ where } } +impl IntoResponse for (R,) +where + R: IntoResponse, +{ + fn into_response(self) -> Response { + let (res,) = self; + res.into_response() + } +} + macro_rules! impl_into_response { ( $($ty:ident),* $(,)? ) => { #[allow(non_snake_case)] diff --git a/axum-macros/tests/debug_handler/fail/wrong_return_type.stderr b/axum-macros/tests/debug_handler/fail/wrong_return_type.stderr index 151c5f84bf..a76569102b 100644 --- a/axum-macros/tests/debug_handler/fail/wrong_return_type.stderr +++ b/axum-macros/tests/debug_handler/fail/wrong_return_type.stderr @@ -9,10 +9,10 @@ error[E0277]: the trait bound `bool: IntoResponse` is not satisfied &'static [u8] &'static str () + (R,) (Response<()>, R) (Response<()>, T1, R) (Response<()>, T1, T2, R) - (Response<()>, T1, T2, T3, R) and $N others note: required by a bound in `__axum_macros_check_handler_into_response::{closure#0}::check` --> tests/debug_handler/fail/wrong_return_type.rs:4:23 diff --git a/axum/CHANGELOG.md b/axum/CHANGELOG.md index 7bb8bd590b..4489c191c6 100644 --- a/axum/CHANGELOG.md +++ b/axum/CHANGELOG.md @@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 # Unreleased -- None. +- **added:** Implement `IntoResponse` for `(R,) where R: IntoResponse` ([#2143]) + +[#2143]: https://github.com/tokio-rs/axum/pull/2143 # 0.6.20 (03. August, 2023)