Skip to content

Commit 2b6ae09

Browse files
authored
Simplify Handler async blocks (#3285)
1 parent 15917c6 commit 2b6ae09

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

axum/CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
# Unreleased
99

1010
- **added:** Implement `From<Bytes>` for `Message` ([#3273])
11+
- **changed:** Improved code size / compile time of `Handler` implementations ([#3285])
1112

1213
[#3273]: https://github.com/tokio-rs/axum/pull/3273
14+
[#3285]: https://github.com/tokio-rs/axum/pull/3285
1315

1416
# 0.8.2
1517

axum/src/handler/mod.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -220,27 +220,23 @@ macro_rules! impl_handler {
220220
type Future = Pin<Box<dyn Future<Output = Response> + Send>>;
221221

222222
fn call(self, req: Request, state: S) -> Self::Future {
223+
let (mut parts, body) = req.into_parts();
223224
Box::pin(async move {
224-
let (mut parts, body) = req.into_parts();
225-
let state = &state;
226-
227225
$(
228-
let $ty = match $ty::from_request_parts(&mut parts, state).await {
226+
let $ty = match $ty::from_request_parts(&mut parts, &state).await {
229227
Ok(value) => value,
230228
Err(rejection) => return rejection.into_response(),
231229
};
232230
)*
233231

234232
let req = Request::from_parts(parts, body);
235233

236-
let $last = match $last::from_request(req, state).await {
234+
let $last = match $last::from_request(req, &state).await {
237235
Ok(value) => value,
238236
Err(rejection) => return rejection.into_response(),
239237
};
240238

241-
let res = self($($ty,)* $last,).await;
242-
243-
res.into_response()
239+
self($($ty,)* $last,).await.into_response()
244240
})
245241
}
246242
}

0 commit comments

Comments
 (0)