From fd60c8471d32db4f7e19b3affabdbcd52c74ce97 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Fri, 27 Dec 2024 11:27:44 +0100 Subject: [PATCH] axum-core/macros: Move `IntoResponse` impls below regular `impl` blocks (#3116) --- axum-core/src/macros.rs | 46 ++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/axum-core/src/macros.rs b/axum-core/src/macros.rs index 44db5b863c..7bca8be90c 100644 --- a/axum-core/src/macros.rs +++ b/axum-core/src/macros.rs @@ -47,6 +47,18 @@ macro_rules! __define_rejection { #[non_exhaustive] pub struct $name; + impl $name { + /// Get the response body text used for this rejection. + pub fn body_text(&self) -> String { + $body.into() + } + + /// Get the status code used for this rejection. + pub fn status(&self) -> http::StatusCode { + http::StatusCode::$status + } + } + impl $crate::response::IntoResponse for $name { fn into_response(self) -> $crate::response::Response { let status = self.status(); @@ -60,18 +72,6 @@ macro_rules! __define_rejection { } } - impl $name { - /// Get the response body text used for this rejection. - pub fn body_text(&self) -> String { - $body.into() - } - - /// Get the status code used for this rejection. - pub fn status(&self) -> http::StatusCode { - http::StatusCode::$status - } - } - impl std::fmt::Display for $name { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", $body) @@ -104,6 +104,16 @@ macro_rules! __define_rejection { { Self($crate::Error::new(err)) } + + /// Get the response body text used for this rejection. + pub fn body_text(&self) -> String { + format!(concat!($body, ": {}"), self.0).into() + } + + /// Get the status code used for this rejection. + pub fn status(&self) -> http::StatusCode { + http::StatusCode::$status + } } impl $crate::response::IntoResponse for $name { @@ -120,18 +130,6 @@ macro_rules! __define_rejection { } } - impl $name { - /// Get the response body text used for this rejection. - pub fn body_text(&self) -> String { - format!(concat!($body, ": {}"), self.0).into() - } - - /// Get the status code used for this rejection. - pub fn status(&self) -> http::StatusCode { - http::StatusCode::$status - } - } - impl std::fmt::Display for $name { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", $body)