[][src]Trait roa::Endpoint

pub trait Endpoint<'a, S>: 'static + Send + Sync {
    fn call<'async_trait>(
        &'a self,
        ctx: &'a mut Context<S>
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'async_trait>>
    where
        'a: 'async_trait,
        Self: 'async_trait
; }

Endpoint

There are two kinds of endpoints, the one is functional endpoints, the another is trait endpoints.

Functional Endpoints

A normal functional endpoint is an object implements Fn trait:

use roa_core::{Context, Next, Result, Endpoint};
use std::future::Future;

fn is_endpoint<S>(endpoint: impl for<'a> Endpoint<'a, S>) {
}

async fn endpoint(ctx: &mut Context<()>) -> Result {
    Ok(())
}

is_endpoint(endpoint);

Closures are also supported, but feature(async_closure) is required:

Trait Endpoints

A trait endpoint is an object implementing trait Endpoint.

use roa_core::{Endpoint, Context, Next, Result, async_trait};
use async_std::sync::Arc;
use std::time::Instant;

fn is_endpoint<S>(endpoint: impl for<'a> Endpoint<'a, S>) {
}

struct Logger;

#[async_trait(?Send)]
impl <'a> Endpoint<'a, ()> for Logger {
    async fn call(&'a self, ctx: &'a mut Context<()>) -> Result {
        Ok(())
    }
}

is_endpoint(Logger);

Required methods

fn call<'async_trait>(
    &'a self,
    ctx: &'a mut Context<S>
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'async_trait>> where
    'a: 'async_trait,
    Self: 'async_trait, 

Call this endpoint.

Loading content...

Implementations on Foreign Types

impl<'a, S> Endpoint<'a, S> for ()[src]

Fake endpoint.

impl<'a, S> Endpoint<'a, S> for Dispatcher<S> where
    S: 'static, 

impl<'a, S, E> Endpoint<'a, S> for Guard<E> where
    E: Endpoint<'a, S>, 

impl<'a, S> Endpoint<'a, S> for RouteTable<S> where
    S: 'static, 

impl<'a, F, S, Fut> Endpoint<'a, S> for Websocket<F, S, Fut> where
    F: 'static + Sync + Send + Fn(Context<S>, WebSocketStream<Upgraded>) -> Fut,
    Fut: 'static + Send + Future<Output = ()>,
    S: State

Loading content...

Implementors

impl<'a, S> Endpoint<'a, S> for Boxed<S> where
    S: 'static, 
[src]

impl<'a, S, T, F> Endpoint<'a, S> for T where
    F: 'a + Future<Output = Result<(), Error>>,
    S: 'a,
    T: 'static + Send + Sync + Fn(&'a mut Context<S>) -> F, 
[src]

impl<'a, S, T, U> Endpoint<'a, S> for Chain<T, U> where
    T: Middleware<'b, S>,
    U: Endpoint<'a, S>, 
[src]

Loading content...