Skip to main content

HandlerFn

Trait HandlerFn 

Source
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§

Source

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".

Implementors§

Source§

impl<F, Fut, R, L> HandlerFn<(L,)> for F
where F: Fn(L) -> Fut + Clone + Send + Sync + 'static, Fut: Future<Output = R> + Send + 'static, R: IntoResponse + 'static, L: FromCall + 'static,

Source§

impl<F, Fut, R, P1, L> HandlerFn<(P1, L)> for F
where F: Fn(P1, L) -> Fut + Clone + Send + Sync + 'static, Fut: Future<Output = R> + Send + 'static, R: IntoResponse + 'static, P1: FromCallParts + 'static, L: FromCall + 'static,

Source§

impl<F, Fut, R, P1, P2, L> HandlerFn<(P1, P2, L)> for F
where F: Fn(P1, P2, L) -> Fut + Clone + Send + Sync + 'static, Fut: Future<Output = R> + Send + 'static, R: IntoResponse + 'static, P1: FromCallParts + 'static, P2: FromCallParts + 'static, L: FromCall + 'static,

Source§

impl<F, Fut, R, P1, P2, P3, L> HandlerFn<(P1, P2, P3, L)> for F
where F: Fn(P1, P2, P3, L) -> Fut + Clone + Send + Sync + 'static, Fut: Future<Output = R> + Send + 'static, R: IntoResponse + 'static, P1: FromCallParts + 'static, P2: FromCallParts + 'static, P3: FromCallParts + 'static, L: FromCall + 'static,

Source§

impl<F, Fut, R, P1, P2, P3, P4, L> HandlerFn<(P1, P2, P3, P4, L)> for F
where F: Fn(P1, P2, P3, P4, L) -> Fut + Clone + Send + Sync + 'static, Fut: Future<Output = R> + Send + 'static, R: IntoResponse + 'static, P1: FromCallParts + 'static, P2: FromCallParts + 'static, P3: FromCallParts + 'static, P4: FromCallParts + 'static, L: FromCall + 'static,

Source§

impl<F, Fut, R, P1, P2, P3, P4, P5, L> HandlerFn<(P1, P2, P3, P4, P5, L)> for F
where F: Fn(P1, P2, P3, P4, P5, L) -> Fut + Clone + Send + Sync + 'static, Fut: Future<Output = R> + Send + 'static, R: IntoResponse + 'static, P1: FromCallParts + 'static, P2: FromCallParts + 'static, P3: FromCallParts + 'static, P4: FromCallParts + 'static, P5: FromCallParts + 'static, L: FromCall + 'static,

Source§

impl<F, Fut, R, P1, P2, P3, P4, P5, P6, L> HandlerFn<(P1, P2, P3, P4, P5, P6, L)> for F
where F: Fn(P1, P2, P3, P4, P5, P6, L) -> Fut + Clone + Send + Sync + 'static, Fut: Future<Output = R> + Send + 'static, R: IntoResponse + 'static, P1: FromCallParts + 'static, P2: FromCallParts + 'static, P3: FromCallParts + 'static, P4: FromCallParts + 'static, P5: FromCallParts + 'static, P6: FromCallParts + 'static, L: FromCall + 'static,

Source§

impl<F, Fut, R, P1, P2, P3, P4, P5, P6, P7, L> HandlerFn<(P1, P2, P3, P4, P5, P6, P7, L)> for F
where F: Fn(P1, P2, P3, P4, P5, P6, P7, L) -> Fut + Clone + Send + Sync + 'static, Fut: Future<Output = R> + Send + 'static, R: IntoResponse + 'static, P1: FromCallParts + 'static, P2: FromCallParts + 'static, P3: FromCallParts + 'static, P4: FromCallParts + 'static, P5: FromCallParts + 'static, P6: FromCallParts + 'static, P7: FromCallParts + 'static, L: FromCall + 'static,

Source§

impl<F, Fut, R, P1, P2, P3, P4, P5, P6, P7, P8, L> HandlerFn<(P1, P2, P3, P4, P5, P6, P7, P8, L)> for F
where F: Fn(P1, P2, P3, P4, P5, P6, P7, P8, L) -> Fut + Clone + Send + Sync + 'static, Fut: Future<Output = R> + Send + 'static, R: IntoResponse + 'static, P1: FromCallParts + 'static, P2: FromCallParts + 'static, P3: FromCallParts + 'static, P4: FromCallParts + 'static, P5: FromCallParts + 'static, P6: FromCallParts + 'static, P7: FromCallParts + 'static, P8: FromCallParts + 'static, L: FromCall + 'static,

Source§

impl<F, Fut, R> HandlerFn<()> for F
where F: Fn() -> Fut + Clone + Send + Sync + 'static, Fut: Future<Output = R> + Send + 'static, R: IntoResponse + 'static,