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);
Fields
primary: A
The primary handler that will have the first chance to process the request.
secondary: B
The secondary handler that will take over if the first handler returns an error.
Methods
impl<A, B> OrElse<A, B>
[src]
impl<A, B> OrElse<A, B>
pub fn new(primary: A, secondary: B) -> OrElse<A, B>
[src]
pub fn new(primary: A, secondary: B) -> OrElse<A, B>
Create a new OrElse
with a primary and secondary handler.
pub fn build(&mut self) -> Builder<A, B>
[src]
pub fn build(&mut self) -> Builder<A, B>
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)); router.build().primary().many(|mut inner_router|{ inner_router.on_get(get as fn(Context, Response)); inner_router.on_post(post); });
impl<A, B: Default> OrElse<A, B>
[src]
impl<A, B: Default> OrElse<A, B>
pub fn with_primary(primary: A) -> OrElse<A, B>
[src]
pub fn with_primary(primary: A) -> OrElse<A, B>
Create a new OrElse
with a given primary and a default secondary handler.
impl<A: Default, B> OrElse<A, B>
[src]
impl<A: Default, B> OrElse<A, B>
pub fn with_secondary(secondary: B) -> OrElse<A, B>
[src]
pub fn with_secondary(secondary: 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>
[src]
impl<A: Clone, B: Clone> Clone for OrElse<A, B>
fn clone(&self) -> OrElse<A, B>
[src]
fn clone(&self) -> OrElse<A, B>
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<A: HandleRequest, B: HandleRequest> HandleRequest for OrElse<A, B>
[src]
impl<A: HandleRequest, B: HandleRequest> HandleRequest for OrElse<A, B>
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<A: Default, B: Default> Default for OrElse<A, B>
[src]
impl<A: Default, B: Default> Default for OrElse<A, B>
impl<'a, A: 'a, B: 'a> Build<'a> for OrElse<A, B>
[src]
impl<'a, A: 'a, B: 'a> Build<'a> for OrElse<A, B>
type Builder = Builder<'a, A, B>
The type that provides the builder API.
fn get_builder(&'a mut self, context: BuilderContext) -> Builder<'a, A, B>
[src]
fn get_builder(&'a mut self, context: BuilderContext) -> Builder<'a, A, B>
Get the builder type for this type, and prepare it with a context.
impl<A: ApplyContext, B: ApplyContext> ApplyContext for OrElse<A, B>
[src]
impl<A: ApplyContext, B: ApplyContext> ApplyContext for OrElse<A, B>
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<A: Merge, B: Merge> Merge for OrElse<A, B>
[src]
impl<A: Merge, B: Merge> Merge for OrElse<A, B>