From c22c22b5bf8609ba9f68b24eaa141ed875ff60b4 Mon Sep 17 00:00:00 2001 From: Payton Turnage Date: Sun, 2 Jul 2017 12:35:03 -0700 Subject: [PATCH] (feat) Added mount! macro to build mounts. --- src/lib.rs | 2 +- src/macros.rs | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/macros.rs diff --git a/src/lib.rs b/src/lib.rs index 9eab0ab..ce0f180 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,4 +10,4 @@ extern crate sequence_trie; pub use mount::{Mount, OriginalUrl}; mod mount; - +mod macros; diff --git a/src/macros.rs b/src/macros.rs new file mode 100644 index 0000000..350285d --- /dev/null +++ b/src/macros.rs @@ -0,0 +1,24 @@ +/// Create a set of mounts. +/// +/// E.g. if you had a directory to serve images from: +/// +/// ```ignore +/// let mount = mount!("/images" => handler_for_image_dir); +/// ``` +/// +/// Is equivalent to: +/// +/// ```ignore +/// let mut mount = Mount::new(); +/// mount.mount("/images", handler_for_image_dir); +/// ``` +/// +/// You may provide multiple mappings, comma-delimited. +#[macro_export] +macro_rules! mount { + ($($path:expr => $handler:expr),+ $(,)*) => ({ + let mut mount = $crate::Mount::new(); + $(mount.mount($path, $handler);)* + mount + }); +}