pub trait Handler:
Clone
+ Send
+ Sync
+ 'static {
type Future: Future<Output = Result<HttpResponse, Error>> + Send + 'static;
// Required method
fn call(&self, req: HttpRequest) -> Self::Future;
}Expand description
A handler that can process HTTP requests.
This trait is designed to be monomorphized: each implementation gets its own specialized code path, allowing the compiler to inline the handler body.
§Example
ⓘ
async fn my_handler(req: HttpRequest) -> Result<HttpResponse, Error> {
Ok(HttpResponse::ok())
}
// The handler is automatically converted via IntoHandler
let handler = my_handler.into_handler();Required Associated Types§
Required Methods§
Sourcefn call(&self, req: HttpRequest) -> Self::Future
fn call(&self, req: HttpRequest) -> Self::Future
Handle an HTTP request.
This method should be inlined by the compiler due to monomorphization. Note: #[inline] hints are applied in implementations, not trait definitions.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.