Skip to content

Commit aa685e3

Browse files
committed
Added mount! macro to simplify the construction of Mount objects
1 parent 5ddd03e commit aa685e3

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ extern crate sequence_trie;
1010
pub use mount::{Mount, OriginalUrl};
1111

1212
mod mount;
13+
mod macros;
1314

src/macros.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
}

0 commit comments

Comments
 (0)