datalog_structural_model/position/
literal_path.rs1use std::fmt;
4
5use super::index::LiteralIndex;
6
7#[derive(
10 Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize,
11)]
12#[serde(transparent)]
13pub struct LiteralPath(
14 Vec<LiteralIndex>,
16);
17
18impl LiteralPath {
19 #[must_use]
21 pub fn top(index: LiteralIndex) -> Self {
22 Self(vec![index])
23 }
24
25 #[must_use]
27 pub fn inner(&self, index: LiteralIndex) -> Self {
28 let mut steps = self.0.clone();
29 steps.push(index);
30 Self(steps)
31 }
32
33 #[must_use]
35 pub fn steps(&self) -> &[LiteralIndex] {
36 &self.0
37 }
38
39 #[must_use]
41 pub fn outer(&self) -> LiteralIndex {
42 self.0[0]
43 }
44}
45
46impl fmt::Display for LiteralPath {
47 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
48 write!(f, "body literal {}", self.0[0].get())?;
49 for step in &self.0[1..] {
50 write!(f, " > inner literal {}", step.get())?;
51 }
52 Ok(())
53 }
54}