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 + }); +}