Crates.io | patricia_router |
lib.rs | patricia_router |
version | 0.1.1 |
source | src |
created_at | 2019-08-22 16:54:17.827172 |
updated_at | 2020-07-05 03:48:40.719944 |
description | Radix Tree implementation for Rust |
homepage | |
repository | https://github.com/TobiasGSmollett/patricia_router |
max_upload_size | |
id | 158914 |
size | 42,210 |
Radix Tree implementation for Rust.
Add this to your application's Cargo.toml
.
[dependencies]
patricia_router = 0.1.0
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");
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
This project has been inspired and adapted from luislavena/radix Crystal implementation, respectively.