matchit
<img alt="crates.io" src="https://img.shields.io/crates/v/matchit?style=for-the-badge" height="25"> <img alt="github" src="https://img.shields.io/badge/github-matchit-blue?style=for-the-badge" height="25"> <img alt="docs.rs" src="https://img.shields.io/docsrs/matchit?style=for-the-badge" height="25">
一个高性能、零拷贝的URL路由器。
use matchit::Router; fn main() -> Result<(), Box<dyn std::error::Error>> { let mut router = Router::new(); router.insert("/home", "欢迎!")?; router.insert("/users/{id}", "一个用户")?; let matched = router.at("/users/978")?; assert_eq!(matched.params.get("id"), Some("978")); assert_eq!(*matched.value, "一个用户"); Ok(()) }
路由器支持动态路由段。这些可以是命名参数或通配符参数。
像/{id}
这样的命名参数可以匹配任何内容,直到下一个/