use std::fmt;
use super::index::LiteralIndex;
#[derive(
Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize,
)]
#[serde(transparent)]
pub struct LiteralPath(
Vec<LiteralIndex>,
);
impl LiteralPath {
#[must_use]
pub fn top(index: LiteralIndex) -> Self {
Self(vec![index])
}
#[must_use]
pub fn inner(&self, index: LiteralIndex) -> Self {
let mut steps = self.0.clone();
steps.push(index);
Self(steps)
}
#[must_use]
pub fn steps(&self) -> &[LiteralIndex] {
&self.0
}
#[must_use]
pub fn outer(&self) -> LiteralIndex {
self.0[0]
}
}
impl fmt::Display for LiteralPath {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "body literal {}", self.0[0].get())?;
for step in &self.0[1..] {
write!(f, " > inner literal {}", step.get())?;
}
Ok(())
}
}