Skip to content

Commit 53370b2

Browse files
authored
axum-core/macros: Change Display impl to match body_text() result (#3118)
1 parent 287bd14 commit 53370b2

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

axum-core/CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
# 0.5.0
1111

12+
- **change:** The `Display` impl of all rejections generated by the
13+
`define_rejection!()` will now include the `Display` output of the
14+
inner error too. This matches the `body_text()` fn output now. ([#3118])
15+
16+
[#3118]: https://github.com/tokio-rs/axum/pull/3118
17+
1218
## rc.1
1319

1420
- **breaking:**: `Option<T>` as an extractor now requires `T` to implement the

axum-core/src/macros.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ macro_rules! __define_rejection {
5050
impl $name {
5151
/// Get the response body text used for this rejection.
5252
pub fn body_text(&self) -> String {
53-
$body.into()
53+
self.to_string()
5454
}
5555

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

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

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

133133
impl std::fmt::Display for $name {
134134
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
135-
write!(f, "{}", $body)
135+
f.write_str($body)?;
136+
f.write_str(": ")?;
137+
self.0.fmt(f)
136138
}
137139
}
138140

0 commit comments

Comments
 (0)