You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: actix-web/MIGRATION-4.0.md
+89-3Lines changed: 89 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -239,11 +239,97 @@ The following is a migration for an error handler that creates a new response in
239
239
240
240
## Middleware Trait APIs
241
241
242
-
This section builds upon guidance from the [response body types](#response-body-types) section.
242
+
The underlying traits that are used for creating middleware, `Service`, `ServiceFactory`, and `Transform`, have changed in design.
243
243
244
-
TODO
244
+
- The associated `Request` type has moved to the type parameter position in order to allow multiple request implementations in other areas of the service stack.
245
+
- The `self` arguments in `Service` have changed from exclusive (mutable) borrows to shared (immutable) borrows. Since most service layers, such as middleware, do not host mutable state, it reduces the runtime overhead in places where a `RefCell` used to be required for wrapping an inner service.
246
+
- We've also introduced some macros that reduce boilerplate when implementing `poll_ready`.
247
+
- Further to the guidance on [response body types](#response-body-types), any use of the old methods on `ServiceResponse` designed to match up body types (e.g., the old `into_body` method), should be replaced with an explicit response body type utilizing `EitherBody<B>`.
println!("Hi from start. You requested: {}", req.path());
317
+
318
+
let fut = self.service.call(req);
319
+
320
+
Box::pin(async move {
321
+
let res = fut.await?;
322
+
323
+
println!("Hi from response");
324
+
Ok(res)
325
+
})
326
+
}
327
+
}
328
+
```
329
+
330
+
This new design is forward-looking and should ease transition to traits that support the upcoming Generic Associated Type (GAT) feature in Rust while also trimming down the boilerplate required to implement middleware.
331
+
332
+
We understand that creating middleware is still a pain point for Actix Web and we hope to provide [an even more ergonomic solution](https://docs.rs/actix-web-lab/0.11.0/actix_web_lab/middleware/fn.from_fn.html) in a v4.x release.
0 commit comments