rust_hdl_core/
named_path.rs

1#[derive(Clone, Debug, PartialEq, Default)]
2pub struct NamedPath {
3    path: Vec<String>,
4    namespace: Vec<String>,
5}
6
7impl NamedPath {
8    pub fn push<T: ToString>(&mut self, x: T) {
9        self.path.push(x.to_string());
10    }
11
12    pub fn pop(&mut self) {
13        self.path.pop();
14    }
15
16    pub fn parent(&self) -> String {
17        self.path[0..self.path.len() - 1]
18            .iter()
19            .map(|x| x.to_string())
20            .collect::<Vec<_>>()
21            .join("$")
22    }
23
24    pub fn last(&self) -> String {
25        self.path.last().unwrap().clone()
26    }
27
28    pub fn reset(&mut self) {
29        self.path.clear();
30    }
31
32    pub fn flat(&self, sep: &str) -> String {
33        self.path.join(sep)
34    }
35
36    pub fn len(&self) -> usize {
37        self.path.len()
38    }
39
40    pub fn is_empty(&self) -> bool {
41        self.path.is_empty()
42    }
43}
44
45impl ToString for NamedPath {
46    fn to_string(&self) -> String {
47        self.path.join("$")
48    }
49}