#router #regexset

reset-recognizer

A RegexSet based route recognizer

4 releases

0.8.0 Jan 21, 2020
0.7.2 Sep 18, 2019
0.7.1 Sep 18, 2019
0.7.0 Sep 16, 2019

#40 in #router

Download history 39/week @ 2021-08-10 56/week @ 2021-08-17 31/week @ 2021-08-24 87/week @ 2021-08-31 72/week @ 2021-09-07 33/week @ 2021-09-14 17/week @ 2021-09-21 67/week @ 2021-09-28 60/week @ 2021-10-05 30/week @ 2021-10-12 49/week @ 2021-10-19 48/week @ 2021-10-26 50/week @ 2021-11-02 41/week @ 2021-11-09 9/week @ 2021-11-16 13/week @ 2021-11-23

117 downloads per month
Used in reset-router

MIT license

12KB
222 lines

reset-recognizer

Docs Crates.io

A fast RegexSet based path router, in the style of route-recognizer.

reset-router, a higher level path router for use with Hyper 0.13, uses this library internally.

Usage:

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));

Current version: 0.8.0

License: MIT

Dependencies

~1–1.3MB
~38K SLoC