Crate bravery_router

Source
Expand description

Bravery router

A radix tree implementation in rust without unsafe code

use bravery_router::{create_root_node, add, optimize, find};

let mut root = create_root_node();
add(&mut root, "/foo", 1);
add(&mut root, "/users/:userId", 2);
add(&mut root, "/*", 3);

let root = optimize(root);

let ret = find(&root, "/foo");
assert_eq!(ret.value, Some(&1));

let ret = find(&root, "/users/42");
assert_eq!(ret.value, Some(&2));
assert_eq!(ret.params, vec!["42"]);

let ret = find(&root, "/bar");
assert_eq!(ret.value, Some(&3));
assert_eq!(ret.params, vec!["bar"]);

Structs§

FindResult
Struct for containing the result of the find function.
Node
Struct for representing a node into the RadixTree.

Functions§

add
Insert into root the value under the path.
create_root_node
Create the root node from which all begins.
find
Find in the radix tree the path and return a FindResult.
optimize
Optimize the radix tree returning the new optimized instance of Node.