pub struct Builder<'a, T: 'a> { /* fields omitted */ }
A builder for a StatusRouter
.
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));
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));
Move handlers from another router into this, overwriting conflicting handlers and properties.