1use crate::types::ViewPathArgs;
2use crate::view::View;
3use regex::Regex;
4use std::sync::Arc;
5
6fn caps_to_map(re: &Regex, caps: ®ex::Captures) -> ViewPathArgs {
7 re.capture_names()
8 .flatten()
9 .filter_map(|n| Some((n.to_owned(), caps.name(n)?.as_str().to_owned())))
10 .collect()
11}
12
13pub fn match_view(
14 routes: &Vec<Arc<dyn View>>,
15 path: &str,
16) -> Option<(Arc<dyn View>, ViewPathArgs)> {
17 for view in routes.iter() {
18 let re = &view.re_path();
19 if let Some(caps) = re.captures(&path) {
20 let view_args = caps_to_map(re, &caps);
21 return Some((view.clone(), view_args));
22 }
23 }
24 None
25}