-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added mount! macro to simplify the construction of Mount objects
- Loading branch information
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,5 @@ extern crate sequence_trie; | |
pub use mount::{Mount, OriginalUrl}; | ||
|
||
mod mount; | ||
mod macros; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |