ibraheemdev / matchit

A high performance, zero-copy URL router.
https://docs.rs/matchit
MIT License
344 stars 35 forks source link

Return iterator of matching routes instead of first match #20

Closed tqwewe closed 2 years ago

tqwewe commented 2 years ago

For something like fall-through routing, it would be useful to return an iterator of values that match the route.

An example might be:

let mut router = Router::new();
router.insert("/users/:id", 1);
router.insert("/users/:name", 2);
router.insert("/users/*", 3);

let mut matches = router.at("/users/ari").iter();
assert_eq!(matches.next(), Some(1));
assert_eq!(matches.next(), Some(2));
assert_eq!(matches.next(), Some(3));
assert_eq!(matches.next(), None);
ibraheemdev commented 2 years ago

This would be a pretty fundamental change to the router. For fallback routing I was thinking of supporting a much simpler model, where conflicting inserts would return the conflicting value. From there you could handle routing guards, etc. yourself.

tqwewe commented 2 years ago

That sounds simpler. In my case, we forked matchit and modified it to our needs, so if it's not in the scope of matchit, feel free to close this issue