actix-web
actix-web copied to clipboard
allow extractors to borrow request
PR Type
Feature
PR Checklist
- [ ] Tests for the changes have been added / updated.
- [ ] Documentation comments have been added / updated.
- [ ] A changelog entry has been made for the appropriate packages.
- [ ] Format code with the latest stable rustfmt.
- [ ] (Team) Label with affected crates and semver status.
Overview
FromRequestX is meant to replace FromRequest. It is implemented as a second trait for prototyping.
Builds on #2450
TODO:
- remove
FromRequest::Output - have
trait FromRequestOwned: for<'a> FromRequest<'a> - have trait
ArgumentFromRequestto mimic the function of Output and have a blanket impl for FromRequestOwned
We can think of this as two separate problem domains:
- support borrowed extractors when using FromRequest methods directly: This can be easily solved by intoducing the lifetime parameter to the trait.
- support borrowed extractors in argument position. See below.
In order to support borrowed extractors in function arguments we need to somehow construct &'a Uri from &'b Uri for any covariant lifetimes <'a, 'b> that appears in the extracted type. This is exactly what FromRequest<'a>::Output is for: for<'a, 'b> <&'a Uri as FromRequestX<'b>>::Output = &'b Uri. and hence FromRequest trait currently serves two puposes: an extractor and a type constructor.
While this works fine for other extractors, a limitation emerges in Path<_> and Query<_>, we need the type constructor function for the inner type T. This todo tries to address this by having two separate traits for the two separate functions: FromRequest<'a> + ArgumentPosExtractor<'a>, so that any extractor with a lifetime parameter need to impl both in order to support being extracted as a handler argument.
Other option is to keep supporting only owned types for Path and Query in argument position, and for zero-copy deserializtion the user can use FromRequest directly in the handler function.