Skip to content

How does Actix know handler arguments? #2542

Answered by robjtede
aunyks asked this question in Q&A
Discussion options

You must be logged in to vote

It's just a trait implemented for functions of various arities. It is the same reason that fn foo(arg: impl Trait) arguments work except that we restrict all the fn arguments to implement FromRequest, too.

The only other interesting part is that we implement FromRequest for tuples up to the same arity which satisfies the T: FromRequest bound you'll see on web::to, for example.

So, we can take the fn arg types, describe them as a tuple, run from_request on the tuple, and get extracted fn args back to call your handler with.

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@robjtede
Comment options

Answer selected by aunyks
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants