Trait highnoon::Endpoint

source ·
pub trait Endpoint<S: State> {
    fn call<'life0, 'async_trait>(
        &'life0 self,
        req: Request<S>
    ) -> Pin<Box<dyn Future<Output = Result<Response>> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        Self: 'async_trait
; }
Expand description

Implement Endpoint for a type to be used as a method handler.

It is already implemented for functions of Request to Result<Response> which is the simplest (and most convenient) kind of handler. You can implement it manually for endpoints that may require some kind of local state.

Endpoint uses the #[async_trait] attribute hence the signature presented in the docs here has been modified. An example of implementing using the attribute:

struct NoOpEndpoint;

#[async_trait::async_trait]
impl<S: State> Endpoint<S> for NoOpEndpoint
{
    async fn call(&self, req: Request<S>) -> Result<Response> {
        Ok(Response::ok())
    }
}

Required Methods

Implementors