3 unstable releases
0.2.1 | May 11, 2022 |
---|---|
0.2.0 | May 4, 2022 |
0.1.0 | Apr 28, 2022 |
#16 in #http-router
15KB
355 lines
pathscheme
A Rust crate that supports describing and matching general path schemes.
License
This program is distributed under the MIT license.
lib.rs
:
A basic path-matching language.
Examples
Path schemes may match literal paths:
assert!("/users/new".parse::<PathScheme>()
.unwrap()
.matches("/users/new")
.unwrap()
.is_empty());
Literal path matching is case-sensitive:
assert!("/users/new".parse::<PathScheme>()
.unwrap()
.matches("/users/New")
.is_none());
Or they may capture path segments:
let matches = "/users/:id".parse::<PathScheme>()
.unwrap()
.matches("/users/olix0r")
.unwrap();
assert!(matches.get("id").unwrap() == "olix0r");
Path schemes must match the entire path:
assert!("/users/:id".parse::<PathScheme>()
.unwrap()
.matches("/users/olix0r/dogs")
.is_none());
A **
glob operator may be used to match path prefixes:
assert!("/users/:id/**".parse::<PathScheme>()
.unwrap()
.matches("/users/olix0r")
.is_some());
assert!("/users/:id/**".parse::<PathScheme>()
.unwrap()
.matches("/users/olix0r/dogs")
.is_some());
Dependencies
~1.2–2MB
~37K SLoC