Skip to content

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