Struct rustful::handler::method_router::MethodRouter
[−]
[src]
pub struct MethodRouter<T> { /* fields omitted */ }
A router that selects a handler from an HTTP method.
It's a simple mapping between Method
and a router T
, while the
requested path is ignored. It's therefore a good idea to pair a
MethodRouter
with an exhaustive path router of some sort.
Methods
impl<T> MethodRouter<T>
[src]
impl<T> MethodRouter<T>
pub fn new() -> MethodRouter<T>
[src]
pub fn new() -> MethodRouter<T>
Create an empty MethodRouter
.
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::MethodRouter; fn get(_context: Context, response: Response) { response.send("A GET request."); } fn post(_context: Context, response: Response) { response.send("A POST request."); } let mut method_router = MethodRouter::<fn(Context, Response)>::new(); method_router.build().many(|mut method_router|{ method_router.on_get(get as fn(Context, Response)); method_router.on_post(post); });
pub fn insert(&mut self, method: Method, handler: T)
[src]
pub fn insert(&mut self, method: Method, handler: T)
Insert a handler that will listen for a specific status code.
use rustful::{Context, Response, Method}; use rustful::handler::{MethodRouter, TreeRouter}; let route_tree = TreeRouter::<Option<fn(Context, Response)>>::new(); //Fill route_tree with handlers... let mut method_router = MethodRouter::new(); method_router.insert(Method::Get, route_tree);
Trait Implementations
impl<T: Clone> Clone for MethodRouter<T>
[src]
impl<T: Clone> Clone for MethodRouter<T>
fn clone(&self) -> MethodRouter<T>
[src]
fn clone(&self) -> MethodRouter<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: HandleRequest> HandleRequest for MethodRouter<T>
[src]
impl<T: HandleRequest> HandleRequest for MethodRouter<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 for MethodRouter<T>
[src]
impl<T> Default for MethodRouter<T>
fn default() -> MethodRouter<T>
[src]
fn default() -> MethodRouter<T>
Returns the "default value" for a type. Read more
impl<'a, T: 'a> Build<'a> for MethodRouter<T>
[src]
impl<'a, T: 'a> Build<'a> for MethodRouter<T>
type Builder = Builder<'a, T>
The type that provides the builder API.
fn get_builder(&'a mut self, context: BuilderContext) -> Self::Builder
[src]
fn get_builder(&'a mut self, context: BuilderContext) -> Self::Builder
Get the builder type for this type, and prepare it with a context.
impl<T: ApplyContext> ApplyContext for MethodRouter<T>
[src]
impl<T: ApplyContext> ApplyContext for MethodRouter<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 MethodRouter<T>
[src]
impl<T: Merge> Merge for MethodRouter<T>
fn merge(&mut self, other: MethodRouter<T>)
[src]
fn merge(&mut self, other: MethodRouter<T>)
Combine this handler with another, overwriting conflicting properties.
Auto Trait Implementations
impl<T> Send for MethodRouter<T> where
T: Send,
impl<T> Send for MethodRouter<T> where
T: Send,
impl<T> Sync for MethodRouter<T> where
T: Sync,
impl<T> Sync for MethodRouter<T> where
T: Sync,