url_match/
lib.rs

1#[macro_use]
2extern crate lazy_static;
3
4extern crate regex;
5
6use std::collections::HashMap;
7
8mod util;
9
10pub fn matcher<'a>(pattern: &'a str, url: &'a str) -> Option<HashMap<String, &'a str>> {
11
12    let mut map = HashMap::new();
13
14    let expr = util::expression(pattern);
15    let re = util::regexp(&expr);
16
17    let caps = re.captures(url)?;
18
19    for (index, key) in re.capture_names().enumerate() {
20        if let (Some(k), Some(c)) = (key, caps.get(index)) {
21            map.insert(k.to_owned(), c.as_str());
22        }
23    }
24
25    Some(map)
26
27}