Skip to content

Commit

Permalink
axum-core/macros: Move IntoResponse impls below regular impl bloc…
Browse files Browse the repository at this point in the history
…ks (#3116)
  • Loading branch information
Turbo87 authored Dec 27, 2024
1 parent 7c934f2 commit fd60c84
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions axum-core/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand Down

0 comments on commit fd60c84

Please sign in to comment.