Trait axum_extra::handler::HandlerCallWithExtractors

source ·
pub trait HandlerCallWithExtractors<T, S>: Sized {
    type Future: Future<Output = Response> + Send + 'static;

    // Required method
    fn call(
        self,
        extractors: T,
        state: S,
    ) -> <Self as HandlerCallWithExtractors<T, S>>::Future;

    // Provided methods
    fn into_handler(self) -> IntoHandler<Self, T, S> { ... }
    fn or<R, Rt>(self, rhs: R) -> Or<Self, R, T, Rt, S>
       where R: HandlerCallWithExtractors<Rt, S> { ... }
}
Expand description

Trait for async functions that can be used to handle requests.

This trait is similar to Handler but rather than taking the request it takes the extracted inputs.

The drawbacks of this trait is that you cannot apply middleware to individual handlers like you can with Handler::layer.

Required Associated Types§

source

type Future: Future<Output = Response> + Send + 'static

The type of future calling this handler returns.

Required Methods§

source

fn call( self, extractors: T, state: S, ) -> <Self as HandlerCallWithExtractors<T, S>>::Future

Call the handler with the extracted inputs.

Provided Methods§

source

fn into_handler(self) -> IntoHandler<Self, T, S>

Convert this HandlerCallWithExtractors into Handler.

source

fn or<R, Rt>(self, rhs: R) -> Or<Self, R, T, Rt, S>
where R: HandlerCallWithExtractors<Rt, S>,

Chain two handlers together, running the second one if the first one rejects.

Note that this only moves to the next handler if an extractor fails. The response from handlers are not considered.

§Example
use axum_extra::handler::HandlerCallWithExtractors;
use axum::{
    Router,
    async_trait,
    routing::get,
    extract::FromRequestParts,
};

// handlers for varying levels of access
async fn admin(admin: AdminPermissions) {
    // request came from an admin
}

async fn user(user: User) {
    // we have a `User`
}

async fn guest() {
    // `AdminPermissions` and `User` failed, so we're just a guest
}

// extractors for checking permissions
struct AdminPermissions {}

#[async_trait]
impl<S> FromRequestParts<S> for AdminPermissions
where
    S: Send + Sync,
{
    // check for admin permissions...
}

struct User {}

#[async_trait]
impl<S> FromRequestParts<S> for User
where
    S: Send + Sync,
{
    // check for a logged in user...
}

let app = Router::new().route(
    "/users/:id",
    get(
        // first try `admin`, if that rejects run `user`, finally falling back
        // to `guest`
        admin.or(user).or(guest)
    )
);

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<F, Fut, S> HandlerCallWithExtractors<(), S> for F
where F: FnOnce() -> Fut, Fut: Future + Send + 'static, Fut::Output: IntoResponse,

§

type Future = Map<Fut, fn(_: <Fut as Future>::Output) -> Response<Body>>

source§

impl<F, Fut, S, T1> HandlerCallWithExtractors<(T1,), S> for F
where F: FnOnce(T1) -> Fut, Fut: Future + Send + 'static, Fut::Output: IntoResponse,

§

type Future = Map<Fut, fn(_: <Fut as Future>::Output) -> Response<Body>>

source§

impl<F, Fut, S, T1, T2> HandlerCallWithExtractors<(T1, T2), S> for F
where F: FnOnce(T1, T2) -> Fut, Fut: Future + Send + 'static, Fut::Output: IntoResponse,

§

type Future = Map<Fut, fn(_: <Fut as Future>::Output) -> Response<Body>>

source§

impl<F, Fut, S, T1, T2, T3> HandlerCallWithExtractors<(T1, T2, T3), S> for F
where F: FnOnce(T1, T2, T3) -> Fut, Fut: Future + Send + 'static, Fut::Output: IntoResponse,

§

type Future = Map<Fut, fn(_: <Fut as Future>::Output) -> Response<Body>>

source§

impl<F, Fut, S, T1, T2, T3, T4> HandlerCallWithExtractors<(T1, T2, T3, T4), S> for F
where F: FnOnce(T1, T2, T3, T4) -> Fut, Fut: Future + Send + 'static, Fut::Output: IntoResponse,

§

type Future = Map<Fut, fn(_: <Fut as Future>::Output) -> Response<Body>>

source§

impl<F, Fut, S, T1, T2, T3, T4, T5> HandlerCallWithExtractors<(T1, T2, T3, T4, T5), S> for F
where F: FnOnce(T1, T2, T3, T4, T5) -> Fut, Fut: Future + Send + 'static, Fut::Output: IntoResponse,

§

type Future = Map<Fut, fn(_: <Fut as Future>::Output) -> Response<Body>>

source§

impl<F, Fut, S, T1, T2, T3, T4, T5, T6> HandlerCallWithExtractors<(T1, T2, T3, T4, T5, T6), S> for F
where F: FnOnce(T1, T2, T3, T4, T5, T6) -> Fut, Fut: Future + Send + 'static, Fut::Output: IntoResponse,

§

type Future = Map<Fut, fn(_: <Fut as Future>::Output) -> Response<Body>>

source§

impl<F, Fut, S, T1, T2, T3, T4, T5, T6, T7> HandlerCallWithExtractors<(T1, T2, T3, T4, T5, T6, T7), S> for F
where F: FnOnce(T1, T2, T3, T4, T5, T6, T7) -> Fut, Fut: Future + Send + 'static, Fut::Output: IntoResponse,

§

type Future = Map<Fut, fn(_: <Fut as Future>::Output) -> Response<Body>>

source§

impl<F, Fut, S, T1, T2, T3, T4, T5, T6, T7, T8> HandlerCallWithExtractors<(T1, T2, T3, T4, T5, T6, T7, T8), S> for F
where F: FnOnce(T1, T2, T3, T4, T5, T6, T7, T8) -> Fut, Fut: Future + Send + 'static, Fut::Output: IntoResponse,

§

type Future = Map<Fut, fn(_: <Fut as Future>::Output) -> Response<Body>>

source§

impl<F, Fut, S, T1, T2, T3, T4, T5, T6, T7, T8, T9> HandlerCallWithExtractors<(T1, T2, T3, T4, T5, T6, T7, T8, T9), S> for F
where F: FnOnce(T1, T2, T3, T4, T5, T6, T7, T8, T9) -> Fut, Fut: Future + Send + 'static, Fut::Output: IntoResponse,

§

type Future = Map<Fut, fn(_: <Fut as Future>::Output) -> Response<Body>>

source§

impl<F, Fut, S, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> HandlerCallWithExtractors<(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10), S> for F
where F: FnOnce(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10) -> Fut, Fut: Future + Send + 'static, Fut::Output: IntoResponse,

§

type Future = Map<Fut, fn(_: <Fut as Future>::Output) -> Response<Body>>

source§

impl<F, Fut, S, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> HandlerCallWithExtractors<(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11), S> for F
where F: FnOnce(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) -> Fut, Fut: Future + Send + 'static, Fut::Output: IntoResponse,

§

type Future = Map<Fut, fn(_: <Fut as Future>::Output) -> Response<Body>>

source§

impl<F, Fut, S, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> HandlerCallWithExtractors<(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12), S> for F
where F: FnOnce(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12) -> Fut, Fut: Future + Send + 'static, Fut::Output: IntoResponse,

§

type Future = Map<Fut, fn(_: <Fut as Future>::Output) -> Response<Body>>

source§

impl<F, Fut, S, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> HandlerCallWithExtractors<(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13), S> for F
where F: FnOnce(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13) -> Fut, Fut: Future + Send + 'static, Fut::Output: IntoResponse,

§

type Future = Map<Fut, fn(_: <Fut as Future>::Output) -> Response<Body>>

source§

impl<F, Fut, S, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14> HandlerCallWithExtractors<(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14), S> for F
where F: FnOnce(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14) -> Fut, Fut: Future + Send + 'static, Fut::Output: IntoResponse,

§

type Future = Map<Fut, fn(_: <Fut as Future>::Output) -> Response<Body>>

source§

impl<F, Fut, S, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> HandlerCallWithExtractors<(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15), S> for F
where F: FnOnce(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15) -> Fut, Fut: Future + Send + 'static, Fut::Output: IntoResponse,

§

type Future = Map<Fut, fn(_: <Fut as Future>::Output) -> Response<Body>>

source§

impl<F, Fut, S, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16> HandlerCallWithExtractors<(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16), S> for F
where F: FnOnce(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16) -> Fut, Fut: Future + Send + 'static, Fut::Output: IntoResponse,

§

type Future = Map<Fut, fn(_: <Fut as Future>::Output) -> Response<Body>>

source§

impl<S, L, R, Lt, Rt> HandlerCallWithExtractors<Either<Lt, Rt>, S> for Or<L, R, Lt, Rt, S>
where L: HandlerCallWithExtractors<Lt, S> + Send + 'static, R: HandlerCallWithExtractors<Rt, S> + Send + 'static, Rt: Send + 'static, Lt: Send + 'static,