Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

axum-core/macros: Change Display impl to match body_text() result #3118

Merged
merged 4 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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