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
find_hyperlinks: bool
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]
impl<T: Default> TreeRouter<T>
pub fn new() -> TreeRouter<T>
[src]
pub fn new() -> TreeRouter<T>
Creates an empty TreeRouter
.
impl<T> TreeRouter<T>
[src]
impl<T> TreeRouter<T>
pub fn with_handler(handler: T) -> TreeRouter<T>
[src]
pub fn with_handler(handler: T) -> TreeRouter<T>
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);
pub fn build(&mut self) -> Builder<T>
[src]
pub fn build(&mut self) -> Builder<T>
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]
impl<T: Clone> Clone for TreeRouter<T>
fn clone(&self) -> TreeRouter<T>
[src]
fn clone(&self) -> TreeRouter<T>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
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]
impl<T: FromHandler<H> + ApplyContext, D: AsRef<[u8]>, H> FromIterator<(Method, D, H)> for TreeRouter<MethodRouter<Variables<T>>>
fn from_iter<I: IntoIterator<Item = (Method, D, H)>>(
iterator: I
) -> TreeRouter<MethodRouter<Variables<T>>>
[src]
fn from_iter<I: IntoIterator<Item = (Method, D, H)>>(
iterator: I
) -> TreeRouter<MethodRouter<Variables<T>>>
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]
impl<T: HandleRequest> HandleRequest for TreeRouter<T>
fn handle_request<'a, 'b, 'l, 'g>(
&self,
environment: Environment<'a, 'b, 'l, 'g>
) -> Result<(), Environment<'a, 'b, 'l, 'g>>
[src]
fn handle_request<'a, 'b, 'l, 'g>(
&self,
environment: Environment<'a, 'b, 'l, 'g>
) -> Result<(), Environment<'a, 'b, 'l, 'g>>
Try to handle an incoming request from the client, or return the request environment to the parent handler. Read more
fn hyperlinks<'a>(&'a self, base: Link<'a>) -> Vec<Link<'a>>
[src]
fn hyperlinks<'a>(&'a self, base: Link<'a>) -> Vec<Link<'a>>
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]
impl<T: Default> Default for TreeRouter<T>
fn default() -> TreeRouter<T>
[src]
fn default() -> TreeRouter<T>
Returns the "default value" for a type. Read more
impl<'a, T: 'a> Build<'a> for TreeRouter<T>
[src]
impl<'a, T: 'a> Build<'a> for TreeRouter<T>
type Builder = Builder<'a, T>
The type that provides the builder API.
fn get_builder(&'a mut self, context: BuilderContext) -> Builder<'a, T>
[src]
fn get_builder(&'a mut self, context: BuilderContext) -> Builder<'a, T>
Get the builder type for this type, and prepare it with a context.
impl<T: FromHandler<H>, H> FromHandler<H> for TreeRouter<T>
[src]
impl<T: FromHandler<H>, H> FromHandler<H> for TreeRouter<T>
fn from_handler(context: BuilderContext, handler: H) -> TreeRouter<T>
[src]
fn from_handler(context: BuilderContext, handler: H) -> TreeRouter<T>
Create a handler from another handler and a BuilderContext
.
impl<T: ApplyContext> ApplyContext for TreeRouter<T>
[src]
impl<T: ApplyContext> ApplyContext for TreeRouter<T>
fn apply_context(&mut self, context: BuilderContext)
[src]
fn apply_context(&mut self, context: BuilderContext)
Set properties, based on a given context.
fn prepend_context(&mut self, context: BuilderContext)
[src]
fn prepend_context(&mut self, context: BuilderContext)
Prepend existing properties, based on a given context.
impl<T: Merge> Merge for TreeRouter<T>
[src]
impl<T: Merge> Merge for TreeRouter<T>
fn merge(&mut self, other: TreeRouter<T>)
[src]
fn merge(&mut self, other: TreeRouter<T>)
Combine this handler with another, overwriting conflicting properties.
Auto Trait Implementations
impl<T> Send for TreeRouter<T> where
T: Send,
impl<T> Send for TreeRouter<T> where
T: Send,
impl<T> Sync for TreeRouter<T> where
T: Sync,
impl<T> Sync for TreeRouter<T> where
T: Sync,