mirror of
https://github.com/tokio-rs/axum.git
synced 2025-09-27 04:50:31 +00:00
Simplify Handler async blocks (#3285)
This commit is contained in:
parent
15917c6dbc
commit
2b6ae09568
@ -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
|
||||
|
||||
|
@ -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()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user