Running into the walking issue again.

This commit is contained in:
Tom Alexander
2020-05-10 21:28:47 -04:00
parent 137e7887a0
commit 4e274b9ea5
2 changed files with 54 additions and 3 deletions

View File

@@ -23,11 +23,13 @@ use std::collections::HashMap;
/// are imposing the cost of copying the data in the renderer because
/// the parser has no reason to not be able to reference data from the
/// input string.
#[derive(Clone, Debug, PartialEq)]
pub enum OwnedRValue {
RVPath(OwnedPath),
RVString(String),
}
#[derive(Clone, Debug, PartialEq)]
pub struct OwnedPath {
pub keys: Vec<String>,
}
@@ -43,6 +45,7 @@ impl From<&RValue<'_>> for OwnedRValue {
}
}
#[derive(Debug)]
pub struct NewParametersContext {
params: HashMap<String, OwnedRValue>,
breadcrumbs: Vec<Box<dyn ContextElement>>,
@@ -67,6 +70,54 @@ impl NewParametersContext {
}
}
impl ContextElement for NewParametersContext {}
impl Renderable for NewParametersContext {
fn render(&self, _filters: &Vec<Filter>) -> Result<String, RenderError> {
// TODO: Would this even ever be called? Won't matter, but I'd
// like to know. Since it is injected 1 above the current
// context, we wouldn't be able to access it with `{.}`.
Ok("[object Object]".to_owned())
}
}
impl Loopable for NewParametersContext {
fn get_loop_elements(&self) -> Vec<&dyn ContextElement> {
// TODO: Would this even ever be called? Won't matter, but I'd
// like to know. Since it is injected 1 above the current
// context, we wouldn't be able to access it with `{.}`.
vec![self]
}
}
impl Walkable for NewParametersContext {
fn walk(&self, segment: &str) -> Result<&dyn ContextElement, WalkError> {
let rval = self.params.get(segment).ok_or(WalkError::CantWalk)?;
match rval {
OwnedRValue::RVPath(path) => walk_path(self.breadcrumbs, &path.keys),
OwnedRValue::RVString(text) => Ok(text),
}
}
}
impl Clone for NewParametersContext {
fn clone(&self) -> Self {
// TODO: What is this doing, really?
*self
}
}
impl CompareContextElement for NewParametersContext {
fn to_any(&self) -> &dyn Any {
self
}
fn equals(&self, other: &dyn ContextElement) -> bool {
// TODO: Does this ever happen? perhaps I should have a panic here.
false
}
}
// #[derive(Clone, Debug)]
// pub struct ParametersContext<'a> {
// params: HashMap<&'a str, &'a RValue<'a>>,