-
I've noticed that all route handler functions don't need to accept the same number or types of arguments. How does Actix know what these arguments are and how to populate them when it receives a request? I assume this happens at compile time. Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
I believe that's a result of this macro that implements Handler for a given Fn type: https://github.com/actix/actix-web/blob/master/src/handler.rs#L65 |
Beta Was this translation helpful? Give feedback.
-
It's just a trait implemented for functions of various arities. It is the same reason that The only other interesting part is that we implement So, we can take the fn arg types, describe them as a tuple, run |
Beta Was this translation helpful? Give feedback.
-
Thanks everyone! |
Beta Was this translation helpful? Give feedback.
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 implementFromRequest
, too.The only other interesting part is that we implement
FromRequest
for tuples up to the same arity which satisfies theT: FromRequest
bound you'll see onweb::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.