Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mount! macro to simplify the construction of Mount objects #79

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jpmartin2
Copy link

I've been doing some work on a simple web application in rust using iron, and while creating the routes for it, I noticed that the router crate had a convenient macro to create the router handler, but mount doesn't. I wanted to be able to write

let handler = mount! {
    "/static" => Static::new(Path::new("path/to/static/files")),
    "/" => router! {
        get "/" => some_other_hanler,
        ...
    },
};

This PR adds the mount! macro so you can write that instead of

let router = router {
    get "/" => some_other_handler,
   ...
};

let mut handler = Mount::new();
handler.mount("/static", Static::new(Path::new("path/to/static/files"));
handler.mount("/", router);

@joshmarlow
Copy link

@iron-bot any thoughts on this?

/// ```ignore
/// let mut mount = Mount::new();
/// mount.mount("/", index);
/// mount.mount("/:query", queryHandler);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this example suggests that mount can deal with variables in paths when it only matches by prefix. Also your macro example says router!, not mount!.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants