#[derive(Debug, Clone)]
pub struct Context {
path: Vec<(String, usize)>
}
impl Context {
pub fn add(&self, item: &str, idx: usize) -> Self {
let mut c = self.clone();
c.path.push((item.to_owned(), idx));
c
}
pub fn new() -> Self {
Self {
path: vec!(),
}
}
pub fn path(&self) -> String {
self.path
.iter()
.map(|(s, i)| {
format!("{}[{}]", s, i)
})
.reduce(|acc, e| format!("{}.{}", acc, e))
.unwrap_or_else(|| "<EMPTY CONTEXT>".to_owned())
}
}