1use core::fmt::Display;
2
3use crate::prelude_internal::*;
4
5#[derive(Debug, Clone, PartialEq, Eq, Hash, Plural)]
6pub struct EurePath(pub Vec<PathSegment>);
7
8impl EurePath {
9 pub fn root() -> Self {
11 EurePath(Vec::new())
12 }
13
14 pub fn is_root(&self) -> bool {
16 self.0.is_empty()
17 }
18}
19
20#[derive(Debug, Clone, PartialEq, Eq, Hash)]
21pub enum PathSegment {
22 Ident(Identifier),
24 Extension(Identifier),
26 Value(ObjectKey),
28 TupleIndex(u8),
30 ArrayIndex(Option<usize>),
32}
33
34impl Display for EurePath {
35 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
36 for segment in &self.0 {
37 match segment {
38 PathSegment::Ident(id) => write!(f, ".{}", id)?,
39 PathSegment::Extension(id) => write!(f, ".${}", id)?,
40 PathSegment::Value(key) => write!(f, ".{}", key)?,
41 PathSegment::TupleIndex(index) => write!(f, ".#{}", index)?,
42 PathSegment::ArrayIndex(Some(index)) => write!(f, "[{}]", index)?,
43 PathSegment::ArrayIndex(None) => write!(f, "[]")?,
44 }
45 }
46 Ok(())
47 }
48}