File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed
Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -10,4 +10,5 @@ extern crate sequence_trie;
1010pub use mount:: { Mount , OriginalUrl } ;
1111
1212mod mount;
13+ mod macros;
1314
Original file line number Diff line number Diff line change 1+ /// Create and populate a mount.
2+ ///
3+ /// ```ignore
4+ /// let router = router!("/" => index,
5+ /// "/:query" => queryHandler)
6+ /// ```
7+ ///
8+ /// Is equivalent to:
9+ ///
10+ /// ```ignore
11+ /// let mut mount = Mount::new();
12+ /// mount.mount("/", index);
13+ /// mount.mount("/:query", queryHandler);
14+ /// ```
15+ #[ macro_export]
16+ macro_rules! mount {
17+ ( $( $mountpoint: expr => $handler: expr) ,+ $( , ) * ) => ( {
18+ let mut mount = $crate:: Mount :: new( ) ;
19+ $( mount. mount( $mountpoint, $handler) ; ) *
20+ mount
21+ } ) ;
22+ }
23+
24+
25+ #[ cfg( test) ]
26+ mod tests {
27+ use iron:: { Response , Request , IronResult } ;
28+
29+ #[ test]
30+ fn methods ( ) {
31+ fn handler ( _: & mut Request ) -> IronResult < Response > { Ok ( Response :: new ( ) ) }
32+ let _ = mount ! ( "/" => handler,
33+ "/foo" => handler) ;
34+ }
35+ }
You can’t perform that action at this time.
0 commit comments