Struct rustful::handler::or_else::OrElse [] [src]

pub struct OrElse<A, B> {
    pub primary: A,
    pub secondary: B,

A router that selects a secondary handler on error.

use rustful::{OrElse, Context, Response};

fn error_handler(_: Context, response: Response) {
    let status = response.status();
    response.send(format!("Status: {}", status));

//Every request will end up at error_handler
let handler = OrElse::<Option<fn(Context, Response)>, _>::new(None, error_handler);


The primary handler that will have the first chance to process the request.

The secondary handler that will take over if the first handler returns an error.


impl<A, B> OrElse<A, B>

Create a new OrElse with a primary and secondary handler.

Build the router and its children using a chaninable API.

use rustful::{Context, Response, OrElse};
use rustful::handler::MethodRouter;

type Inner = MethodRouter<fn(Context, Response)>;

fn get(_context: Context, response: Response) {
    response.send("A GET request.");

fn post(_context: Context, response: Response) {
    response.send("A POST request.");

fn or_else(_context: Context, response: Response) {
    response.send("Hello world!");

let mut router = OrElse::<Inner, _>::with_secondary(or_else as fn(Context, Response));|mut inner_router|{
    inner_router.on_get(get as fn(Context, Response));

impl<A, B: Default> OrElse<A, B>

Create a new OrElse with a given primary and a default secondary handler.

impl<A: Default, B> OrElse<A, B>

Create a new OrElse with a given secondary and a default primary handler.

Trait Implementations

impl<A: Clone, B: Clone> Clone for OrElse<A, B>

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<A: HandleRequest, B: HandleRequest> HandleRequest for OrElse<A, B>

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<A: Default, B: Default> Default for OrElse<A, B>

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

impl<'a, A: 'a, B: 'a> Build<'a> for OrElse<A, B>

The type that provides the builder API.

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

impl<A: ApplyContext, B: ApplyContext> ApplyContext for OrElse<A, B>

Set properties, based on a given context.

Prepend existing properties, based on a given context.

impl<A: Merge, B: Merge> Merge for OrElse<A, B>

Combine this handler with another, overwriting conflicting properties.

Auto Trait Implementations

impl<A, B> Send for OrElse<A, B> where
    A: Send,
    B: Send

impl<A, B> Sync for OrElse<A, B> where
    A: Sync,
    B: Sync