1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
use super::Route; use super::Router; /// Builder for a router /// /// Example usage: /// #[derive(Debug)] pub struct RouterBuilder { routes: Vec<Route>, } impl RouterBuilder { pub fn new() -> RouterBuilder { RouterBuilder { routes: vec![] } } /// Adds new `Route` for `Router` that is being built. /// /// Example: /// /// ```ignore /// use hyper::server::{Request, Response}; /// use hyper_router::{Route, RouterBuilder}; /// /// fn some_handler(_: Request) -> Response { /// // do something /// } /// /// RouterBuilder::new().add(Route::get(r"/person/\d+").using(some_handler)); /// ``` pub fn add(mut self, route: Route) -> RouterBuilder { self.routes.push(route); self } pub fn build(self) -> Router { Router { routes: self.routes } } }