patricia_router

Crates.iopatricia_router
lib.rspatricia_router
version0.1.1
sourcesrc
created_at2019-08-22 16:54:17.827172
updated_at2020-07-05 03:48:40.719944
descriptionRadix Tree implementation for Rust
homepage
repositoryhttps://github.com/TobiasGSmollett/patricia_router
max_upload_size
id158914
size42,210
Ryuya Takahashi (TobiasGSmollett)

documentation

README

patricia_router

crate-name at crates.io crate-name at docs.rs Build Status codecov

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.

Commit count: 4

cargo fmt