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 resolvedFut: 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);