[][src]Struct saphir::router::Builder

pub struct Builder<Chain: RouterChain + Send + Unpin + 'static + Sync> { /* fields omitted */ }

Builder type for the router

Implementations

impl<Controllers: 'static + RouterChain + Unpin + Send + Sync> Builder<Controllers>[src]

pub fn route<H>(self, route: &str, method: Method, handler: H) -> Self where
    H: 'static + DynHandler<Body> + Send + Sync
[src]

Add a simple request handle to a given path

// Simply declare a handler fn
async fn simple_handler(req: Request<Body>) -> impl Responder {200}

// Then while building your server
// ...
builder.route("/simple", Method::GET, simple_handler);
// ...

pub fn route_with_guards<H, F, Chain>(
    self,
    route: &str,
    method: Method,
    handler: H,
    guards: F
) -> Self where
    H: 'static + DynHandler<Body> + Send + Sync,
    F: FnOnce(GuardBuilder<GuardChainEnd>) -> GuardBuilder<Chain>,
    Chain: GuardChain + 'static, 
[src]

Add a request handler to a given path behind guards


async fn handler(req: Request<Body>) -> impl Responder { 200 }

async fn value_guard(req: Request<Body>) -> Result<Request<Body>, u16> {
   match req.captures().get("value") {
       Some(v) if v.eq("allowed_value") => Ok(req),
       Some(_) => Err(403),
       None => Err(400),
   }
}

builder.route_with_guards("/handler/{value}", Method::GET, handler, |g| {
    g.apply(value_guard)
});
// ...

pub fn controller<C: Controller + Send + Unpin + Sync>(
    self,
    controller: C
) -> Builder<RouterChainLink<C, Controllers>>
[src]

Add a simple request handle to a given path

// Implement controller for your struct
struct SimpleController;
// Then while building your server
// ...
builder.controller(SimpleController);
// ...

Trait Implementations

impl Default for Builder<RouterChainEnd>[src]

Auto Trait Implementations

impl<Chain> !RefUnwindSafe for Builder<Chain>

impl<Chain> Send for Builder<Chain>

impl<Chain> Sync for Builder<Chain>

impl<Chain> Unpin for Builder<Chain>

impl<Chain> UnwindSafe for Builder<Chain> where
    Chain: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.