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

pub struct StatusRouter<T> { /* fields omitted */ }

A router that selects an item from an HTTP status code.

It does neither alter nor preserve the status code of the response.


impl<T> StatusRouter<T>

Create an empty StatusRouter.

Build the router and its children using a chaninable API.

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();|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};
use rustful::handler::MethodRouter;

let on_not_found = MethodRouter::<fn(Context, Response)>::new();
//Fill on_not_found with handlers...

let mut status_router = StatusRouter::new();
status_router.insert(StatusCode::NotFound, on_not_found);

Trait Implementations

impl<T: Clone> Clone for StatusRouter<T>

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<T: HandleRequest> HandleRequest for StatusRouter<T>

Try to handle an incoming request from the client, or return the request environment to the parent handler. Read more

List all of the hyperlinks into this handler, based on the provided base link. It's up to the handler implementation to decide how deep to go. Read more

impl<T> Default for StatusRouter<T>

Returns the "default value" for a type. Read more

impl<'a, T: 'a> Build<'a> for StatusRouter<T>

The type that provides the builder API.

Get the builder type for this type, and prepare it with a context.

impl<T: ApplyContext> ApplyContext for StatusRouter<T>

Set properties, based on a given context.

Prepend existing properties, based on a given context.

impl<T: Merge> Merge for StatusRouter<T>

Combine this handler with another, overwriting conflicting properties.

Auto Trait Implementations

impl<T> Send for StatusRouter<T> where
    T: Send

impl<T> Sync for StatusRouter<T> where
    T: Sync