teo_runtime/handler/
match.rs

1use std::sync::Arc;
2use indexmap::IndexMap;
3
4#[derive(Debug, Clone)]
5pub struct HandlerMatch {
6    inner: Arc<Inner>,
7}
8
9#[derive(Debug, Clone)]
10struct Inner {
11    path: Vec<String>,
12    name: String,
13    captures: IndexMap<String, String>,
14    path_without_last: Vec<String>,
15}
16
17impl HandlerMatch {
18
19    pub fn new(path: Vec<String>, name: String, captures: IndexMap<String, String>) -> Self {
20        let mut path_without_last = path.clone();
21        path_without_last.pop();
22        Self {
23            inner: Arc::new(Inner {
24                path,
25                name,
26                captures,
27                path_without_last,
28            })
29        }
30    }
31
32    pub fn path_without_last(&self) -> &Vec<String> {
33        &self.inner.path_without_last
34    }
35
36    pub fn group_name(&self) -> &str {
37        self.path().last().unwrap()
38    }
39
40    pub fn path(&self) -> &Vec<String> {
41        &self.inner.path
42    }
43
44    pub fn name(&self) -> &str {
45        self.inner.name.as_str()
46    }
47
48    pub fn handler_name(&self) -> &str {
49        self.inner.name.as_str()
50    }
51
52    pub fn captures(&self) -> &IndexMap<String, String> {
53        &self.inner.captures
54    }
55}