1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use serde::Serialize;

#[derive(Clone, PartialEq, Eq, Hash, Debug, Serialize)]
pub struct Reference {
    path: Vec<usize>,
    string_path: Vec<String>,
}

impl Reference {

    pub fn new(path: Vec<usize>, string_path: Vec<String>) -> Self {
        Self { path, string_path, }
    }

    pub fn path(&self) -> &Vec<usize> {
        &self.path
    }

    pub fn path_without_last(&self, n: usize) -> Vec<usize> {
        self.path().iter().rev().skip(n).rev().map(Clone::clone).collect()
    }

    pub fn str_path(&self) -> Vec<&str> {
        self.string_path.iter().map(AsRef::as_ref).collect()
    }

    pub fn string_path(&self) -> &Vec<String> {
        &self.string_path
    }

    pub fn str_path_without_last(&self, n: usize) -> Vec<&str> {
        self.string_path.iter().map(AsRef::as_ref).rev().skip(n).rev().collect()
    }
}