github: https://github.com/Ilqjx/radixtree
Cargo.toml
radixtree = "0.1"
use radixtree::{Node, Method};
fn main() {
let mut tree = Node::new();
tree.insert(Method::GET, "/hello", "hello");
tree.insert(Method::GET, "/user/$id", "user");
tree.insert(Method::GET, "/image/*", "image");
let result = tree.search(Method::GET, "/hello");
assert!(result.is_some());
assert_eq!(result.unwrap().value(), &"hello");
let result = tree.search(Method::GET, "/user/1001");
assert!(result.is_some());
assert_eq!(result.unwrap().value(), &"user");
let result = tree.search(Method::GET, "/image/hello.png");
assert!(result.is_some());
assert_eq!(result.unwrap().value(), &"image");
tree.update(Method::GET, "/hello", "UPDATE hello");
tree.update(Method::GET, "/user/$id", "UPDATE user");
tree.update(Method::GET, "/image/*", "UPDATE image");
let result = tree.search(Method::GET, "/hello");
assert!(result.is_some());
assert_eq!(result.unwrap().value(), &"UPDATE hello");
let result = tree.search(Method::GET, "/user/1002");
assert!(result.is_some());
assert_eq!(result.unwrap().value(), &"UPDATE user");
let result = tree.search(Method::GET, "/image/hi.jpg");
assert!(result.is_some());
assert_eq!(result.unwrap().value(), &"UPDATE image");
tree.remove("/hello");
tree.remove("/user/$id");
tree.remove("/image/*");
let result = tree.search(Method::GET, "/hello");
assert!(result.is_none());
let result = tree.search(Method::GET, "/user/1003");
assert!(result.is_none());
let result = tree.search(Method::GET, "/image/hi.gif");
assert!(result.is_none());
}