Skip to content

How to utilize the lifetime of &mut Parts when implementing FromRequestParts. #2189

Closed Answered by jplatte
twitchax asked this question in Q&A
Discussion options

You must be logged in to vote

You can't borrow from the request in handlers with the current trait, and axum intentionally doesn't use lifetime generics in there, partly because that would just make the trait harder to grasp for users. But also, the current design has the FromRequest trait consume the request, which is incompatible with keeping borrows to the request around for the handler function.

The only thing you can do to avoid cloning is to take ownership of the header by removing it from the headers (which means it won't be available for subsequent extractors).

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@twitchax
Comment options

@jplatte
Comment options

Answer selected by davidpdrsn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants