Trait RequestHandler

Source
pub trait RequestHandler {
    // Required method
    fn handle<'life0, 'async_trait>(
        &'life0 self,
        request: Request,
    ) -> Pin<Box<dyn Future<Output = Result<Response>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

A function that takes a request and returns a response.

This is the main building block of a Cot app. You shouldn’t usually need to implement this directly, as it is already implemented for closures and functions that take a Request and return a Result<Response>.

Required Methods§

Source

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

Handle the request and returns a response.

§Errors

This method can return an error if the request handler fails to handle the request.

Implementors§

Source§

impl<T, R> RequestHandler for T
where T: Fn(Request) -> R + Clone + Send + Sync + 'static, R: for<'a> Future<Output = Result<Response>> + Send,