wayfind
A speedy, flexible router for Rust.
Why another router?
Real-world projects often need advanced routing: inline parameters, mid-route wildcards, or compatibility with frameworks like Ruby on Rails and specifications like the OCI Distribution Specification.
wayfind aims to be competitive with the fastest routers while supporting these features. Unused features don't impact performance.
Showcase
[]
= "*"
use Error;
use RouterBuilder;
let mut builder = new;
builder.insert?;
builder.insert?;
builder.insert?;
builder.insert?;
builder.insert?;
builder.insert?;
builder.insert?;
let router = builder.build;
let search = router.search.unwrap;
assert_eq!;
assert_eq!;
let search = router.search.unwrap;
assert_eq!;
assert_eq!;
let search = router.search.unwrap;
assert_eq!;
assert_eq!;
let search = router.search.unwrap;
assert_eq!;
assert_eq!;
let search = router.search.unwrap;
assert_eq!;
assert_eq!;
let search = router.search.unwrap;
assert_eq!;
assert_eq!;
let search = router.search.unwrap;
assert_eq!;
assert_eq!;
println!;
Ok::
/v2
╰─ /
╰─ <*name>
╰─ /
├─ blobs/
│ ├─ uploads
│ │ ╰─ /
│ │ ╰─ <reference>
│ ╰─ <algorithm>
│ ╰─ :
│ ╰─ <hash>
├─ manifests/
│ ╰─ <reference>
├─ referrers/
│ ╰─ <algorithm>
│ ╰─ :
│ ╰─ <hash>
╰─ tags/list
Implementation Details
wayfind stores routes in a compressed radix trie.
When searching, each node tries its children in priority order:
- static
- dynamic
- wildcard
All parameters are greedy, consuming as much of the path as possible.
Limitations
There is no backtracking across priority levels. This can result in some matches which may be unexpected.
In the following router:
/api/
├─ <version>
│ ╰─ /
│ ╰─ <*rest>
╰─ <*path>
╰─ /help
The path /api/docs/help would match the first route, not the second.
Even though the second is arguably more specific.
Performance
wayfind is competitive with the fastest Rust routers across all benchmarks we run.
For all benchmarks, we convert any extracted parameters to strings.
All routers provide a way to return parameters as strings, but some delay the actual UTF-8 decoding until post-search.
| Library | Percent Decoding | String Parameters |
|---|---|---|
| wayfind | no | yes |
| actix-router | partial | yes |
| matchit | no | delayed |
| ntex-router | partial | yes |
| path-tree | no | delayed |
| route-recognizer | no | yes |
| xitca-router | no | yes |
As such, we provide 2 sets of results per benchmark:
- one with the default behaviour of the router.
- one with the parameters extracted to
Vec<(&str, &str)>.
See the results at: https://codspeed.io/DuskSystems/wayfind/benchmarks
License
wayfind is licensed under the terms of both the MIT License and the Apache License (Version 2.0).