1
0
Fork 0
mirror of https://github.com/tokio-rs/axum.git synced 2025-04-26 13:56:22 +02:00

Make status a const function in rejection handling ()

Signed-off-by: Awiteb <a@4rs.nl>
This commit is contained in:
Mohammed Alotaibi 2025-01-11 21:50:32 +03:00 committed by GitHub
parent 28c6be74ae
commit e09cc59365
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 17 additions and 5 deletions
axum-core
axum-extra
axum
CHANGELOG.md
src/extract/path

View file

@ -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

View file

@ -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
}
}
@ -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
}
}
@ -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(),

View file

@ -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

View file

@ -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

View file

@ -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 { .. }
@ -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
}
}