2 releases
0.1.1 | Jul 5, 2020 |
---|---|
0.1.0 | Aug 22, 2019 |
#773 in Data structures
21 downloads per month
Used in craft
31KB
611 lines
patricia_router
Radix Tree implementation for Rust.
Installation
Add this to your application's Cargo.toml
.
[dependencies]
patricia_router = 0.1.0
Usage
let mut router = Router::<&str>::new();
router.add("/", "root");
router.add("/*filepath", "all");
router.add("/products", "products");
router.add("/products/:id", "product");
router.add("/products/:id/edit", "edit");
router.add("/products/featured", "featured");
let mut result = router.find("/products/featured");
assert_eq!(result.key(), "/products/featured");
assert_eq!(result.payload, &Some("featured"));
// named parameters match a single path segment
result = router.find("/products/1000");
assert_eq!(result.key(), "/products/:id");
assert_eq!(result.payload, &Some("product"));
// catch all parameters match everything
result = router.find("/admin/articles");
assert_eq!(result.key(), "/*filepath");
assert_eq!(result.params("filepath"), "admin/articles");
Development
Run tests following commands.
$ cargo test
$ rustup install nightly
$ cargo +nightly bench
Code submitted to this repository should be formatted according to cargo +nightly fmt
.
$ rustup toolchain install nightly
$ cargo +nightly fmt
Implementation
This project has been inspired and adapted from luislavena/radix Crystal implementation, respectively.