#router #regexset #routes #hyper #path #13 #regex-set

reset-recognizer

基于 RegexSet 的路由识别器

4 个版本

0.8.0 2020年1月21日
0.7.2 2019年9月18日
0.7.1 2019年9月18日
0.7.0 2019年9月16日

#99#routes

40 每月下载量
用于 reset-router

MIT 许可证

13KB
222 代码行

reset-recognizer

Docs Crates.io

一个快速的基于 RegexSet 的路径路由器,类似于 route-recognizer

reset-router,一个用于 Hyper 0.13 的高层路径路由器,内部使用此库。

用法

let router = reset_recognizer::Router::build()
    .add(r"^/posts/(.+)/comments/(.+)$", "comment".to_string())
    .add(r"^/posts/(.+)/comments$", "comments".to_string())
    .add(r"^/posts/(.+)$", "post".to_string())
    .add(r"^/posts$", "posts".to_string())
    .add(r"^/comments$", "comments2".to_string())
    .add(r"^/comments/(.+)$", "comment2".to_string())
    .add_with_priority(r"^/(.+)$", 1, "not_found".to_string())
    .finish()?;

let matched = router.recognize("/posts/100/comments/200")?;

let (post_id, comment_id) = matched.captures.parsed::<(i32, i32)>()?;

println!("{:?}", (&matched.handler, &post_id, &comment_id));

当前版本:0.8.0

许可证:MIT

依赖

~2.2–3MB
~53K SLoC