teo_parser/type/
reference.rs1use serde::Serialize;
2
3#[derive(Clone, PartialEq, Eq, Hash, Debug, Serialize)]
4pub struct Reference {
5 path: Vec<usize>,
6 string_path: Vec<String>,
7}
8
9impl Reference {
10
11 pub fn new(path: Vec<usize>, string_path: Vec<String>) -> Self {
12 Self { path, string_path, }
13 }
14
15 pub fn path(&self) -> &Vec<usize> {
16 &self.path
17 }
18
19 pub fn path_without_last(&self, n: usize) -> Vec<usize> {
20 self.path().iter().rev().skip(n).rev().map(Clone::clone).collect()
21 }
22
23 pub fn str_path(&self) -> Vec<&str> {
24 self.string_path.iter().map(AsRef::as_ref).collect()
25 }
26
27 pub fn string_path(&self) -> &Vec<String> {
28 &self.string_path
29 }
30
31 pub fn str_path_without_last(&self, n: usize) -> Vec<&str> {
32 self.string_path.iter().map(AsRef::as_ref).rev().skip(n).rev().collect()
33 }
34
35 pub fn string_path_without_last(&self, n: usize) -> Vec<String> {
36 self.string_path.iter().map(ToString::to_string).rev().skip(n).rev().collect()
37 }
38}