For now Router is using path-table for its route matching. Consider changing the algorithm by replacing it with [route_recognizer].
The published version of route_recognizer is unmaintained for about 2 years, and seems to have reversed precedence of path segment matching (conduit-rust/route-recognizer.rs#21). Maybe we can fork the repository and apply some patches.
Related to #12. route_recognizer seems to have more sophiscated route matching algorithm than path-table. I expect it to fix most of the counterintuitive cases.
There is actix_router, but it is Independent锛宎nd dont dependent Actix* . It is General
this is one test
Note: this is the algorithm ultimately used by crates.io:
so it's "maintained", just hasn't needed a lot of updating. Definitely a worthy candidate to look at, and I expect the current owners would be interested in moving it into the rust-net-web org.
One thing to consider for the router API is a way of providing reverse lookups #24. I'll go into more detail about the small survey I did of current implementation of such an API in django and flask, but both of them leverage the router to provide a reverse lookups of endpoints to paths for building URLs.
So, we need a router that:
path-table currently used by Tide addresses only the second point, and both route_recognizer and actix-router don't have reverse lookup feature (as far as I understand). I think we need to fork and add needed functionality anyway, so how about experimenting with route_recognizer? It might be challenging with state machines, though.
I wrote a crate https://github.com/trek-rs/path-tree.
supports reverse lookups
supports named and catch-all likes https://github.com/julienschmidt/httprouter, but more flexible.
Currently, I am thinking about how to generate urls. Maybe the {} is best syntax.
The #156 PR moved to route-recognizer. And in general it should now be much easier to swap out the underlying router. I'm open to moving to path-tree if that seems like a better option -- though offhand the two seem pretty comparable in terms of functionality (and route-recognizer is used by crates.io, so there's some impetus for sharing).
I'm going to close this for now, but if @fundon or others want to explore moving from route-recognizer to path-tree or something else, please feel free to open a new issue and make a case there!
Most helpful comment
I wrote a crate https://github.com/trek-rs/path-tree.
supports reverse lookups
supports
namedandcatch-alllikes https://github.com/julienschmidt/httprouter, but more flexible.Currently, I am thinking about how to generate urls. Maybe the
{}is best syntax.