1use std::collections::{BTreeMap};
2
3#[derive(Clone,Debug)]
4pub struct Path {
5 pub url: String,
7 pub map: Vec<(i32, String)>,
9}
10
11impl Path {
12 pub fn new(url: &str) -> Self {
13 let url = &url[0..url.find("?").unwrap_or(url.len())];
14 let args: Vec<&str> = url.split("/").collect();
15 let mut map = Vec::new();
16 let mut idx = 0;
17 for x in args {
18 if x.starts_with("{") && x.ends_with("}") {
19 map.push((idx, x.trim_start_matches("{").trim_end_matches("}").to_string()));
20 }
21 idx += 1;
22 }
23 Self {
24 url: url.to_string(),
25 map: map,
26 }
27 }
28
29 pub fn read_path(&self, url: &str) -> BTreeMap<String, String> {
30 let url = &url[0..url.find("?").unwrap_or(url.len())];
31 let args: Vec<&str> = url.split("/").collect();
32 let mut params = BTreeMap::new();
33 let mut idx = 0;
34 for x in args {
35 for (i, v) in &self.map {
36 if *i == idx {
37 params.insert(v.to_string(), x.to_string());
38 }
39 }
40 idx += 1;
41 }
42 params
43 }
44}