Skip to content

Commit

Permalink
axum-core/macros: Change Display impl to match body_text() result (
Browse files Browse the repository at this point in the history
  • Loading branch information
Turbo87 authored Dec 27, 2024
1 parent 287bd14 commit 53370b2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 6 additions & 0 deletions axum-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

# 0.5.0

- **change:** The `Display` impl of all rejections generated by the
`define_rejection!()` will now include the `Display` output of the
inner error too. This matches the `body_text()` fn output now. ([#3118])

[#3118]: https://github.com/tokio-rs/axum/pull/3118

## rc.1

- **breaking:**: `Option<T>` as an extractor now requires `T` to implement the
Expand Down
8 changes: 5 additions & 3 deletions axum-core/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ macro_rules! __define_rejection {
impl $name {
/// Get the response body text used for this rejection.
pub fn body_text(&self) -> String {
$body.into()
self.to_string()
}

/// Get the status code used for this rejection.
Expand Down Expand Up @@ -107,7 +107,7 @@ macro_rules! __define_rejection {

/// Get the response body text used for this rejection.
pub fn body_text(&self) -> String {
format!(concat!($body, ": {}"), self.0).into()
self.to_string()
}

/// Get the status code used for this rejection.
Expand All @@ -132,7 +132,9 @@ macro_rules! __define_rejection {

impl std::fmt::Display for $name {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", $body)
f.write_str($body)?;
f.write_str(": ")?;
self.0.fmt(f)
}
}

Expand Down

0 comments on commit 53370b2

Please sign in to comment.