Radix Tree implementation for Rust.
Add this to your application's Cargo.toml
.
sh
[dependencies]
patricia_router = 0.1.0
```rust 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"); asserteq!(result.key(), "/products/featured"); asserteq!(result.payload, &Some("featured"));
// named parameters match a single path segment result = router.find("/products/1000"); asserteq!(result.key(), "/products/:id"); asserteq!(result.payload, &Some("product"));
// catch all parameters match everything result = router.find("/admin/articles"); asserteq!(result.key(), "/*filepath"); asserteq!(result.params("filepath"), "admin/articles"); ```
Run tests following commands. ```sh $ cargo test
$ rustup install nightly $ cargo +nightly bench ```
Code submitted to this repository should be formatted according to cargo +nightly fmt
.
sh
$ rustup toolchain install nightly
$ cargo +nightly fmt
This project has been inspired and adapted from luislavena/radix Crystal implementation, respectively.