IntoHandler

Trait IntoHandler 

Source
pub trait IntoHandler<T>:
    Clone
    + Send
    + Sync
    + 'static {
    // Required method
    fn call<'async_trait>(
        self,
        req: Request,
    ) -> Pin<Box<dyn Future<Output = Result<Response>> + Send + 'async_trait>>
       where Self: 'async_trait;
}
Expand description

Trait for converting functions into handlers.

This trait is similar to UniversalHandler but specifically for handlers that return Result<Response>. It provides a bridge between regular async functions and the handler system.

The type parameter T represents the extractor types used by the handler.

§Type Parameter

  • T - Tuple representing the extractor types

Required Methods§

Source

fn call<'async_trait>( self, req: Request, ) -> Pin<Box<dyn Future<Output = Result<Response>> + Send + 'async_trait>>
where Self: 'async_trait,

Call the handler and return a Result<Response>.

§Arguments
  • req - The HTTP request to process
§Returns

Returns Result<Response>, allowing handlers to propagate errors.

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.

Implementors§

Source§

impl<F, Fut> IntoHandler<(RawRequest,)> for F
where F: Fn(Request) -> Fut + Clone + Send + Sync + 'static, Fut: Future<Output = Result<Response>> + Send + 'static,

Implementation for functions that take RawRequest directly.

This allows handlers to receive the complete Request object without going through the extraction system.

Source§

impl<F, Fut> IntoHandler<()> for F
where F: Fn() -> Fut + Clone + Send + Sync + 'static, Fut: Future<Output = Result<Response>> + Send + 'static,

Implementation for functions with no extractors that just return Response.

This allows simple functions that don’t need request data to be used as handlers.

§Examples

use ignitia::{Response, Result};

// This function implements IntoHandler<()>
async fn health_check() -> Result<Response> {
    Ok(Response::json(serde_json::json!({
        "status": "healthy",
        "timestamp": chrono::Utc::now().to_rfc3339()
    }))?)
}