Skip to content

Commit

Permalink
Make status a const function in rejection handling (#3168)
Browse files Browse the repository at this point in the history
Signed-off-by: Awiteb <[email protected]>
  • Loading branch information
TheAwiteb authored Jan 11, 2025
1 parent 28c6be7 commit e09cc59
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
6 changes: 6 additions & 0 deletions axum-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

# Unreleased

- **change:** Make the `status` function for rejections generated by the
`__define_rejection` and `__composite_rejection` macros a `const` function
([#3168])

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

# 0.5.0

## since rc.1
Expand Down
6 changes: 3 additions & 3 deletions axum-core/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ macro_rules! __define_rejection {
}

/// Get the status code used for this rejection.
pub fn status(&self) -> http::StatusCode {
pub const fn status(&self) -> http::StatusCode {
http::StatusCode::$status
}
}
Expand Down Expand Up @@ -111,7 +111,7 @@ macro_rules! __define_rejection {
}

/// Get the status code used for this rejection.
pub fn status(&self) -> http::StatusCode {
pub const fn status(&self) -> http::StatusCode {
http::StatusCode::$status
}
}
Expand Down Expand Up @@ -188,7 +188,7 @@ macro_rules! __composite_rejection {
}

/// Get the status code used for this rejection.
pub fn status(&self) -> http::StatusCode {
pub const fn status(&self) -> http::StatusCode {
match self {
$(
Self::$variant(inner) => inner.status(),
Expand Down
3 changes: 3 additions & 0 deletions axum-extra/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ and this project adheres to [Semantic Versioning].
- **breaking:** Remove unused `async-stream` feature, which was accidentally
introduced as an implicit feature through an optional dependency which was no
longer being used ([#3145])
- **change:** Make the `status` function of rejections a `const` function, such
as `FormRejection`, `QueryRejection` and `MultipartRejection` ([#3168])

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

# 0.10.0

Expand Down
3 changes: 3 additions & 0 deletions axum/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

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

[#3142]: https://github.com/tokio-rs/axum/pull/3142
[#3157]: https://github.com/tokio-rs/axum/pull/3157
[#3168]: https://github.com/tokio-rs/axum/pull/3168

# 0.8.0

Expand Down
4 changes: 2 additions & 2 deletions axum/src/extract/path/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ impl FailedToDeserializePathParams {
}

/// Get the status code used for this rejection.
pub fn status(&self) -> StatusCode {
pub const fn status(&self) -> StatusCode {
match self.0.kind {
ErrorKind::Message(_)
| ErrorKind::DeserializeError { .. }
Expand Down Expand Up @@ -563,7 +563,7 @@ impl InvalidUtf8InPathParam {
}

/// Get the status code used for this rejection.
pub fn status(&self) -> StatusCode {
pub const fn status(&self) -> StatusCode {
StatusCode::BAD_REQUEST
}
}
Expand Down

0 comments on commit e09cc59

Please sign in to comment.