Struct rustful::handler::status_router::Builder [] [src]

pub struct Builder<'a, T: 'a> { /* fields omitted */ }

A builder for a StatusRouter.

Methods

impl<'a, T> Builder<'a, T>
[src]

Perform more than one operation on this builder.

use rustful::{Context, Response, StatusCode, StatusRouter};

fn on_404(context: Context, response: Response) {
    response.send(format!("{} was not found.", context.uri_path));
}

fn on_500(_: Context, response: Response) {
    response.send("Looks like you found a bug");
}
let mut status_router = StatusRouter::<fn(Context, Response)>::new();

status_router.build().many(|mut status_router|{
    status_router.on(StatusCode::NotFound, on_404 as fn(Context, Response));
    status_router.on(StatusCode::InternalServerError, on_500);
});

Insert a handler that will listen for a specific status code.

use rustful::{Context, Response, StatusCode, StatusRouter};

fn on_404(context: Context, response: Response) {
    response.send(format!("{} was not found.", context.uri_path));
}

let mut status_router = StatusRouter::<fn(Context, Response)>::new();
status_router.build().on(StatusCode::NotFound, on_404 as fn(Context, Response));

impl<'a: 'b, 'b, T: Default + ApplyContext + Build<'b>> Builder<'a, T>
[src]

Build a handler that will listen for a specific status code.

use rustful::{Context, Response, StatusCode, StatusRouter};
use rustful::handler::MethodRouter;

fn on_get_404(context: Context, response: Response) {
    response.send(format!("GET {} was not found.", context.uri_path));
}

let mut status_router = StatusRouter::<MethodRouter<fn(Context, Response)>>::new();

status_router.build()
    .status(StatusCode::NotFound)
    .on_get(on_get_404 as fn(Context, Response));

impl<'a, T: Merge + ApplyContext> Builder<'a, T>
[src]

Move handlers from another router into this, overwriting conflicting handlers and properties.

Trait Implementations

Auto Trait Implementations

impl<'a, T> !Send for Builder<'a, T>

impl<'a, T> !Sync for Builder<'a, T>