Struct rustful::handler::tree_router::TreeRouter [] [src]

pub struct TreeRouter<T> {
    pub find_hyperlinks: bool,
    // some fields omitted
}

A tree shaped router that selects handlers using paths.

Each tree node stores an other router of type T, which has to implement Default to allow "empty" nodes, and a number of child references. The requested path must always be exhausted before sub-routers are searched, so there is no point in storing other path based routers in a TreeRouter.

The TreeRouter has support for shallow hyperlinks to children, siblings, cousins, and so forth. The use of variable sequences complicates this process and may cause confusing results in certain situations. The hyperlinks may or may not point to a handler.

Hyperlinks has to be activated by setting find_hyperlinks to true.

Fields

Should the router search for hyperlinks? Setting this to true may slow down endpoint search, but enables hyperlinks.

Methods

impl<T: Default> TreeRouter<T>
[src]

Creates an empty TreeRouter.

impl<T> TreeRouter<T>
[src]

Creates a TreeRouter with only a root handler.

use rustful::{Context, Response};
use rustful::handler::TreeRouter;

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

let router = TreeRouter::with_handler(handler);

Build the router and its children using a chaninable API.

use rustful::{Context, Response};
use rustful::handler::TreeRouter;

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

let mut router = TreeRouter::<Option<fn(Context, Response)>>::new();
router.build().on_path("hello/world", handler);

Trait Implementations

impl<T: Clone> Clone for TreeRouter<T>
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<T: FromHandler<H> + ApplyContext, D: AsRef<[u8]>, H> FromIterator<(Method, D, H)> for TreeRouter<MethodRouter<Variables<T>>>
[src]

Create a DefaultRouter from a collection of routes.

extern crate rustful;
use rustful::Method::Get;

let routes = vec![
    (Get, "/about", about_us),
    (Get, "/users", list_users),
    (Get, "/users/:id", show_user),
    (Get, "/products", list_products),
    (Get, "/products/:id", show_product),
    (Get, "/*", show_error),
    (Get, "/", show_welcome)
];

let router: DefaultRouter<ExampleHandler> = routes.into_iter().collect();

impl<T: HandleRequest> HandleRequest for TreeRouter<T>
[src]

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> Default for TreeRouter<T>
[src]

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

impl<'a, T: 'a> Build<'a> for TreeRouter<T>
[src]

The type that provides the builder API.

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

impl<T: FromHandler<H>, H> FromHandler<H> for TreeRouter<T>
[src]

Create a handler from another handler and a BuilderContext.

impl<T: ApplyContext> ApplyContext for TreeRouter<T>
[src]

Set properties, based on a given context.

Prepend existing properties, based on a given context.

impl<T: Merge> Merge for TreeRouter<T>
[src]

Combine this handler with another, overwriting conflicting properties.

Auto Trait Implementations

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

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