pub struct Builder<'a, T: 'a> { /* fields omitted */ }
A builder for a TreeRouter
.
Add a path to the router and keep building the resulting node.
use rustful::{Context, Response};
use rustful::handler::TreeRouter;
fn handler1(_context: Context, response: Response) {
response.send("Hello world 1!");
}
fn handler2(_context: Context, response: Response) {
response.send("Hello world 2!");
}
let mut router = TreeRouter::<Option<fn(Context, Response)>>::new();
router.build().path("hello/world").many(|mut node| {
node.on_route("1", handler1);
node.on_route("2", handler2);
});
Add a handler at the end of a path and keep building the resulting node.
use rustful::{Context, Response};
use rustful::handler::TreeRouter;
fn handler(_context: Context, response: Response) {
response.send("Hello world!");
}
fn handler1(_context: Context, response: Response) {
response.send("Hello world 1!");
}
fn handler2(_context: Context, response: Response) {
response.send("Hello world 2!");
}
let mut router = TreeRouter::<Option<fn(Context, Response)>>::new();
router.build().on_path("hello/world", handler).many(|mut node| {
node.on_route("1", handler1);
node.on_route("2", handler2);
});
Perform more than one operation on this builder.
use rustful::{Context, Response};
use rustful::handler::TreeRouter;
fn handler1(_context: Context, response: Response) {
response.send("Hello world 1!");
}
fn handler2(_context: Context, response: Response) {
response.send("Hello world 2!");
}
let mut router = TreeRouter::<Option<fn(Context, Response)>>::new();
router.build().many(|mut node| {
node.on_route("1", handler1);
node.on_route("2", handler2);
});
Add a handler at the end of a route segment and keep building the resulting node.
use rustful::{Context, Response};
use rustful::handler::TreeRouter;
fn handler(_context: Context, response: Response) {
response.send("Hello world!");
}
fn handler1(_context: Context, response: Response) {
response.send("Hello world 1!");
}
fn handler2(_context: Context, response: Response) {
response.send("Hello world 2!");
}
let mut router = TreeRouter::<Option<fn(Context, Response)>>::new();
router.build().on_route("hello_world", handler).many(|mut node| {
node.on_route("1", handler1);
node.on_route("2", handler2);
});
Try to get a node at the end of an existing path.
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().path("hello/world");
router.build().get_path("hello/world").expect("where did it go?!").handler(handler);
Set or replace the handler at the current node.
Build the handler at the current node.
use rustful::{Context, Response};
use rustful::handler::{TreeRouter, MethodRouter};
fn handler(_context: Context, response: Response) {
response.send("Hello world!");
}
let mut router = TreeRouter::<MethodRouter<fn(Context, Response)>>::new();
router.build().path("hello/world").then().on_get(handler);
Move handlers from another router into this, overwriting conflicting handlers and properties.