Skip to content

Commit

Permalink
Added mount! macro to simplify the construction of Mount objects
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmartin2 committed Mar 28, 2016
1 parent 5ddd03e commit aa685e3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ extern crate sequence_trie;
pub use mount::{Mount, OriginalUrl};

mod mount;
mod macros;

35 changes: 35 additions & 0 deletions src/macros.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/// Create and populate a mount.
///
/// ```ignore
/// let router = router!("/" => index,
/// "/:query" => queryHandler)
/// ```
///
/// Is equivalent to:
///
/// ```ignore
/// let mut mount = Mount::new();
/// mount.mount("/", index);
/// mount.mount("/:query", queryHandler);
/// ```
#[macro_export]
macro_rules! mount {
($($mountpoint:expr => $handler:expr),+ $(,)*) => ( {
let mut mount = $crate::Mount::new();
$(mount.mount($mountpoint, $handler);)*
mount
});
}


#[cfg(test)]
mod tests {
use iron::{Response, Request, IronResult};

#[test]
fn methods() {
fn handler(_: &mut Request) -> IronResult<Response> {Ok(Response::new())}
let _ = mount!("/" => handler,
"/foo" => handler);
}
}

0 comments on commit aa685e3

Please sign in to comment.