Skip to main content

Crate wildcard_trie

Crate wildcard_trie 

Source
Expand description

§Radix Trie for URL Routing

A space-efficient trie that compresses paths by storing common prefixes in single nodes. This prevents DoS attacks from extremely long segmented paths while maintaining fast lookups.

This crate supports:

  • Wildcard Support: Routes ending in /* match any sub-path
  • Fast Lookups: O(path_length)`` instead of O(number_of_routes)`
  • DoS Resistant: Long paths don’t create excessive nodes
  • Compressed representation: /api/v1/users and /api/v1/posts share the /api/v1/ prefix

§Example

use wildcard_trie::Trie;

let mut trie = Trie::new();
trie.insert("/api/*", "api_handler");           // Wildcard
trie.insert("/api/users", "users_handler");     // Exact (takes precedence)

assert_eq!(trie.get("/api/users"), Some(&"users_handler"));  // Exact match
assert_eq!(trie.get("/api/posts"), Some(&"api_handler"));    // Wildcard match

Structs§

Trie
A radix trie for efficient path-based routing with wildcard support