matchit icon indicating copy to clipboard operation
matchit copied to clipboard

Return iterator of matching routes instead of first match

Open tqwewe opened this issue 3 years ago • 2 comments

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);

tqwewe avatar Jun 16 '22 08:06 tqwewe

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.

ibraheemdev avatar Jun 27 '22 17:06 ibraheemdev

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

tqwewe avatar Jun 28 '22 05:06 tqwewe