feat(router): Add chainable routes - #288
Conversation
There was a problem hiding this comment.
These should work with &'a mut self rather than &static ..
|
@Ryman Thanks very much for the help. Seems to be working now. Please take a look again when you have a chance and let me know if you have any feedback. I'm still very much new to rust. So, any feedback is appreciated. One question I had was whether Rust can distinguish between trait methods with the same name but different arity. When I try to import both my chainable router impls and the HttpRouter ones, I get a compilation error that the "get" method for example exists in both traits. So I'm thinking it can't tell that they have different signatures/arities. Maybe this is just a limitation of rust at the moment? |
Yep, there's no such thing as method overloading in Rust and it's probably unlikely to be implemented. However, you can always just shift syntax to specifically tell the compiler which method to invoke. So, instead of writing this which would be forbidden: use TraitWithGet;
use OtherTraitWithGet;
some_thing.get();
some_thing.get(true); //compiler errorYou could write: use TraitWithGet;
use OtherTraitWithGet;
TraitWithGet::get(some_thing);
OtherTraitWithGet::get(some_thing, true);I didn't test it out but I'm pretty sure it should work. UPDATE Corrected syntax according to @Ryman 's comment. Stupid me ;) |
|
What @cburgdorf is referring to is UFCS but it should be You shouldn't really be running into the method name clash unless you've implemented both traits for a given type though? (has the code changed?) Inference should be able to see that the return from |
Right, that's true. I confused myself. I had an intermediate implementation where I was just adding the last path added with |
|
@Ryman @cburgdorf Is there anything I can do to improve this? Any feedback is appreciated as I'm new with rust. |
There was a problem hiding this comment.
I think this can be &'a str, or you might need to introduce a new lifetime 'b if the route chaining is to work (haven't tried)
There was a problem hiding this comment.
Yeah I'm trying to hack around my limitations in understanding lifetimes. I'll try that and see if I can get it working with an &str.
|
@mattbanister Sorry for the delay, I've left some feedback :) At a higher level though, do you think you might want to publish this as a crate? I think it builds nicely around the core so I think it would be a good example of how to make extensions to nickel if you wished to do so! |
|
Hi @Ryman Thanks for the feedback. I think that would be great to make it a separate crate. I'll work on that and your other comments this week. I really appreciate the help! |
This doesn't work yet but I'm putting up the PR because I could use some help with it.