Open fintelia opened 7 years ago
Hi! Thank you for reporting this! This macro has been removed in master
, due to how inflexible it is, but I can make a maintenance branch if there's no way to work around this and a fix can be figured out. The tricky part is to detect if mut
is necessary or not.
Do you own the router, as in the example above? In that case you can try something like this:
let mut router = TreeRouter::new();
let router = insert_routes! {
router => {
"graph" => Get: Box::new(move |_: Context, _: Response| {}) as Box<Handler>,
}
};
I think fixing the warning should simply be a matter of having #[allow(unused_mut)]
on the assignment statement.
However, in my use case there is no particular reason that I have to use insert_routes
, and it would probably be better to move away from it if the macro has been deprecated. What is the suggested replacement for it? For reference, the code that is currently relying on it is here.
I think fixing the warning should simply be a matter of having #[allow(unused_mut)] on the assignment statement.
I'm forgetting that this is possible these days... That could be a good idea.
In the meantime, it looks like you can use the method I showed before, but if you want to move away from the macro, it seems like you will be fine with the insert
method. That's what's used behind the scenes, and you are not really using the tree structure of the macro anyway.
The released version doesn't have the new ways of building routers, so your tools are listed here: https://docs.rs/rustful/0.9.0/rustful/struct.TreeRouter.html, unless you feel like using the master
branch. It's a bit different, but you will not get any surprise breaks if you lock it to a commit.
Example code to reproduce:
which expands to:
And the actual warning message: