Simplify Handler async blocks (#3285)

This commit is contained in:
Jonas Platte 2025-03-25 13:07:35 +01:00 committed by GitHub
parent 15917c6dbc
commit 2b6ae09568
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 8 deletions

View File

@ -8,8 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
# Unreleased
- **added:** Implement `From<Bytes>` for `Message` ([#3273])
- **changed:** Improved code size / compile time of `Handler` implementations ([#3285])
[#3273]: https://github.com/tokio-rs/axum/pull/3273
[#3285]: https://github.com/tokio-rs/axum/pull/3285
# 0.8.2

View File

@ -220,12 +220,10 @@ macro_rules! impl_handler {
type Future = Pin<Box<dyn Future<Output = Response> + Send>>;
fn call(self, req: Request, state: S) -> Self::Future {
let (mut parts, body) = req.into_parts();
Box::pin(async move {
let (mut parts, body) = req.into_parts();
let state = &state;
$(
let $ty = match $ty::from_request_parts(&mut parts, state).await {
let $ty = match $ty::from_request_parts(&mut parts, &state).await {
Ok(value) => value,
Err(rejection) => return rejection.into_response(),
};
@ -233,14 +231,12 @@ macro_rules! impl_handler {
let req = Request::from_parts(parts, body);
let $last = match $last::from_request(req, state).await {
let $last = match $last::from_request(req, &state).await {
Ok(value) => value,
Err(rejection) => return rejection.into_response(),
};
let res = self($($ty,)* $last,).await;
res.into_response()
self($($ty,)* $last,).await.into_response()
})
}
}