Skip to content

Commit e09cc59

Browse files
authored
Make status a const function in rejection handling (#3168)
Signed-off-by: Awiteb <[email protected]>
1 parent 28c6be7 commit e09cc59

File tree

5 files changed

+17
-5
lines changed

5 files changed

+17
-5
lines changed

axum-core/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
# Unreleased
99

10+
- **change:** Make the `status` function for rejections generated by the
11+
`__define_rejection` and `__composite_rejection` macros a `const` function
12+
([#3168])
13+
14+
[#3168]: https://github.com/tokio-rs/axum/pull/3168
15+
1016
# 0.5.0
1117

1218
## since rc.1

axum-core/src/macros.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ macro_rules! __define_rejection {
5454
}
5555

5656
/// Get the status code used for this rejection.
57-
pub fn status(&self) -> http::StatusCode {
57+
pub const fn status(&self) -> http::StatusCode {
5858
http::StatusCode::$status
5959
}
6060
}
@@ -111,7 +111,7 @@ macro_rules! __define_rejection {
111111
}
112112

113113
/// Get the status code used for this rejection.
114-
pub fn status(&self) -> http::StatusCode {
114+
pub const fn status(&self) -> http::StatusCode {
115115
http::StatusCode::$status
116116
}
117117
}
@@ -188,7 +188,7 @@ macro_rules! __composite_rejection {
188188
}
189189

190190
/// Get the status code used for this rejection.
191-
pub fn status(&self) -> http::StatusCode {
191+
pub const fn status(&self) -> http::StatusCode {
192192
match self {
193193
$(
194194
Self::$variant(inner) => inner.status(),

axum-extra/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ and this project adheres to [Semantic Versioning].
1010
- **breaking:** Remove unused `async-stream` feature, which was accidentally
1111
introduced as an implicit feature through an optional dependency which was no
1212
longer being used ([#3145])
13+
- **change:** Make the `status` function of rejections a `const` function, such
14+
as `FormRejection`, `QueryRejection` and `MultipartRejection` ([#3168])
1315

1416
[#3145]: https://github.com/tokio-rs/axum/pull/3145
17+
[#3168]: https://github.com/tokio-rs/axum/pull/3168
1518

1619
# 0.10.0
1720

axum/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
- **added:** Implement `OptionalFromRequest` for `Json` ([#3142])
1111
- **added:** Implement `OptionalFromRequest` for `Extension` ([#3157])
12+
- **change:** Make the `status` function of rejections a `const` function, such
13+
as `JsonRejection`, `QueryRejection` and `PathRejection` ([#3168])
1214

1315
[#3142]: https://github.com/tokio-rs/axum/pull/3142
1416
[#3157]: https://github.com/tokio-rs/axum/pull/3157
17+
[#3168]: https://github.com/tokio-rs/axum/pull/3168
1518

1619
# 0.8.0
1720

axum/src/extract/path/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ impl FailedToDeserializePathParams {
429429
}
430430

431431
/// Get the status code used for this rejection.
432-
pub fn status(&self) -> StatusCode {
432+
pub const fn status(&self) -> StatusCode {
433433
match self.0.kind {
434434
ErrorKind::Message(_)
435435
| ErrorKind::DeserializeError { .. }
@@ -563,7 +563,7 @@ impl InvalidUtf8InPathParam {
563563
}
564564

565565
/// Get the status code used for this rejection.
566-
pub fn status(&self) -> StatusCode {
566+
pub const fn status(&self) -> StatusCode {
567567
StatusCode::BAD_REQUEST
568568
}
569569
}

0 commit comments

Comments
 (0)