FnTrait

Trait FnTrait 

Source
pub trait FnTrait<Args>: Send + Sync {
    type Output;
    type Fut: Future<Output = Self::Output> + Send;

    // Required method
    fn call(&self, args: Args) -> Self::Fut;
}
Expand description

A trait for abstracting over async functions with varying numbers of parameters.

This trait allows the web framework to work with different types of handler functions in a uniform way, regardless of their parameter count or types.

§Type Parameters

  • Args: The tuple type containing all function parameters

§Associated Types

  • Output: The type that the function returns when resolved
  • Fut: The specific Future type that the function returns

§Examples

use http::Method;///

use micro_web::FnTrait;

async fn my_handler(method: &Method) -> String {
    format!("Handling {} request", method)
}

// The function automatically implements FnTrait
fn assert_handler<'r, F: FnTrait<(&'r Method,)>>(f: F) {}
assert_handler(my_handler);

Required Associated Types§

Source

type Output

Source

type Fut: Future<Output = Self::Output> + Send

Required Methods§

Source

fn call(&self, args: Args) -> Self::Fut

Implementors§

Source§

impl<Func, Fut> FnTrait<()> for Func
where Func: Fn() -> Fut + Send + Sync, Fut: Future + Send,

Source§

type Output = <Fut as Future>::Output

Source§

type Fut = Fut

Source§

impl<Func, Fut, A> FnTrait<(A,)> for Func
where Func: Fn(A) -> Fut + Send + Sync, Fut: Future + Send,

Source§

type Output = <Fut as Future>::Output

Source§

type Fut = Fut

Source§

impl<Func, Fut, A, B> FnTrait<(A, B)> for Func
where Func: Fn(A, B) -> Fut + Send + Sync, Fut: Future + Send,

Source§

type Output = <Fut as Future>::Output

Source§

type Fut = Fut

Source§

impl<Func, Fut, A, B, C> FnTrait<(A, B, C)> for Func
where Func: Fn(A, B, C) -> Fut + Send + Sync, Fut: Future + Send,

Source§

type Output = <Fut as Future>::Output

Source§

type Fut = Fut

Source§

impl<Func, Fut, A, B, C, D> FnTrait<(A, B, C, D)> for Func
where Func: Fn(A, B, C, D) -> Fut + Send + Sync, Fut: Future + Send,

Source§

type Output = <Fut as Future>::Output

Source§

type Fut = Fut

Source§

impl<Func, Fut, A, B, C, D, E> FnTrait<(A, B, C, D, E)> for Func
where Func: Fn(A, B, C, D, E) -> Fut + Send + Sync, Fut: Future + Send,

Source§

type Output = <Fut as Future>::Output

Source§

type Fut = Fut

Source§

impl<Func, Fut, A, B, C, D, E, F> FnTrait<(A, B, C, D, E, F)> for Func
where Func: Fn(A, B, C, D, E, F) -> Fut + Send + Sync, Fut: Future + Send,

Source§

type Output = <Fut as Future>::Output

Source§

type Fut = Fut

Source§

impl<Func, Fut, A, B, C, D, E, F, G> FnTrait<(A, B, C, D, E, F, G)> for Func
where Func: Fn(A, B, C, D, E, F, G) -> Fut + Send + Sync, Fut: Future + Send,

Source§

type Output = <Fut as Future>::Output

Source§

type Fut = Fut

Source§

impl<Func, Fut, A, B, C, D, E, F, G, H> FnTrait<(A, B, C, D, E, F, G, H)> for Func
where Func: Fn(A, B, C, D, E, F, G, H) -> Fut + Send + Sync, Fut: Future + Send,

Source§

type Output = <Fut as Future>::Output

Source§

type Fut = Fut

Source§

impl<Func, Fut, A, B, C, D, E, F, G, H, I> FnTrait<(A, B, C, D, E, F, G, H, I)> for Func
where Func: Fn(A, B, C, D, E, F, G, H, I) -> Fut + Send + Sync, Fut: Future + Send,

Source§

type Output = <Fut as Future>::Output

Source§

type Fut = Fut

Source§

impl<Func, Fut, A, B, C, D, E, F, G, H, I, J> FnTrait<(A, B, C, D, E, F, G, H, I, J)> for Func
where Func: Fn(A, B, C, D, E, F, G, H, I, J) -> Fut + Send + Sync, Fut: Future + Send,

Source§

type Output = <Fut as Future>::Output

Source§

type Fut = Fut

Source§

impl<Func, Fut, A, B, C, D, E, F, G, H, I, J, K> FnTrait<(A, B, C, D, E, F, G, H, I, J, K)> for Func
where Func: Fn(A, B, C, D, E, F, G, H, I, J, K) -> Fut + Send + Sync, Fut: Future + Send,

Source§

type Output = <Fut as Future>::Output

Source§

type Fut = Fut

Source§

impl<Func, Fut, A, B, C, D, E, F, G, H, I, J, K, L> FnTrait<(A, B, C, D, E, F, G, H, I, J, K, L)> for Func
where Func: Fn(A, B, C, D, E, F, G, H, I, J, K, L) -> Fut + Send + Sync, Fut: Future + Send,

Source§

type Output = <Fut as Future>::Output

Source§

type Fut = Fut