pub trait HandlerFn<Marker>:
Clone
+ Send
+ Sync
+ 'static {
// Required method
fn call(self, call: Call) -> HandlerFuture;
}Expand description
Bridge trait implemented by handler closures of a given arity. The LAST
closure argument is FromCall (consuming); all earlier ones are
FromCallParts (borrowing). Handlers must be Clone so the closure can be
moved into the 'static response future.
IMPLEMENTATION NOTE (why this is not the spec’s literal macro): the plan’s
Step 2 shows a macro that emits impl<...> Handler for F directly for each
arity. That design does NOT compile on stable Rust: the coherence checker
treats impl Handler for F where F: Fn(), ... F: Fn(A), ... F: Fn(A, B)
etc. as mutually overlapping, because a single closure type could in
principle implement several Fn traits of different arities (E0119 on every
arity). A disambiguating Marker type parameter is required to keep the
per-arity impls disjoint — the standard axum-style pattern. The public
Handler trait, BoxHandler, and boxed keep the spec signatures; this
HandlerFn family is the closure-side bridge that is adapted into a
Handler via IntoHandler (see below). This trait is pub only because
it appears in the bound of IntoHandler/the router’s method builders; it is
intentionally NOT re-exported from the crate root.
Required Methods§
Sourcefn call(self, call: Call) -> HandlerFuture
fn call(self, call: Call) -> HandlerFuture
Run the closure against the call: extract each argument from the call in
order, then invoke the closure and convert its return value into a
Response.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".