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.
Methods
impl<T> StatusRouter<T>
[src]
impl<T> StatusRouter<T>
pub fn new() -> StatusRouter<T>
[src]
pub fn new() -> StatusRouter<T>
Create an empty StatusRouter
.
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, 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(); status_router.build().many(|mut status_router|{ status_router.on(StatusCode::NotFound, on_404 as fn(Context, Response)); status_router.on(StatusCode::InternalServerError, on_500); });
pub fn insert(&mut self, status: StatusCode, handler: T)
[src]
pub fn insert(&mut self, status: StatusCode, handler: T)
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>
[src]
impl<T: Clone> Clone for StatusRouter<T>
fn clone(&self) -> StatusRouter<T>
[src]
fn clone(&self) -> StatusRouter<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 StatusRouter<T>
[src]
impl<T: HandleRequest> HandleRequest for StatusRouter<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 StatusRouter<T>
[src]
impl<T> Default for StatusRouter<T>
fn default() -> StatusRouter<T>
[src]
fn default() -> StatusRouter<T>
Returns the "default value" for a type. Read more
impl<'a, T: 'a> Build<'a> for StatusRouter<T>
[src]
impl<'a, T: 'a> Build<'a> for StatusRouter<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: ApplyContext> ApplyContext for StatusRouter<T>
[src]
impl<T: ApplyContext> ApplyContext for StatusRouter<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 StatusRouter<T>
[src]
impl<T: Merge> Merge for StatusRouter<T>
fn merge(&mut self, other: StatusRouter<T>)
[src]
fn merge(&mut self, other: StatusRouter<T>)
Combine this handler with another, overwriting conflicting properties.
Auto Trait Implementations
impl<T> Send for StatusRouter<T> where
T: Send,
impl<T> Send for StatusRouter<T> where
T: Send,
impl<T> Sync for StatusRouter<T> where
T: Sync,
impl<T> Sync for StatusRouter<T> where
T: Sync,