Commenting out the parameterscontext type.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use crate::parser::KVPair;
|
||||
use crate::parser::{Filter, RValue};
|
||||
use crate::renderer::context_element::ContextElement;
|
||||
use crate::renderer::context_element::IntoBoxedContextElement;
|
||||
use crate::renderer::walking::walk_path;
|
||||
use crate::renderer::Loopable;
|
||||
use crate::renderer::RenderError;
|
||||
@@ -57,6 +58,7 @@ impl NewParametersContext {
|
||||
|
||||
let x: String = "foo".to_owned();
|
||||
let y: &dyn ContextElement = &x as _;
|
||||
let z: Box<dyn ContextElement> = y.clone().to_box();
|
||||
// let owned_y: Box<dyn ContextElement> = Box::new(*y.clone());
|
||||
// unsafe {
|
||||
// let ce = &mut *y.clone() as *mut dyn ContextElement;
|
||||
@@ -73,57 +75,57 @@ impl NewParametersContext {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ParametersContext<'a> {
|
||||
params: HashMap<&'a str, &'a RValue<'a>>,
|
||||
breadcrumbs: &'a Vec<&'a dyn ContextElement>,
|
||||
}
|
||||
// #[derive(Clone, Debug)]
|
||||
// pub struct ParametersContext<'a> {
|
||||
// params: HashMap<&'a str, &'a RValue<'a>>,
|
||||
// breadcrumbs: &'a Vec<&'a dyn ContextElement>,
|
||||
// }
|
||||
|
||||
impl<'a> ParametersContext<'a> {
|
||||
pub fn new(
|
||||
breadcrumbs: &'a Vec<&'a dyn ContextElement>,
|
||||
params: &'a Vec<KVPair<'a>>,
|
||||
) -> ParametersContext<'a> {
|
||||
let param_map = params
|
||||
.iter()
|
||||
.map(|pair: &KVPair<'a>| (pair.key, &pair.value))
|
||||
.collect();
|
||||
ParametersContext {
|
||||
params: param_map,
|
||||
breadcrumbs: breadcrumbs,
|
||||
}
|
||||
}
|
||||
}
|
||||
// impl<'a> ParametersContext<'a> {
|
||||
// pub fn new(
|
||||
// breadcrumbs: &'a Vec<&'a dyn ContextElement>,
|
||||
// params: &'a Vec<KVPair<'a>>,
|
||||
// ) -> ParametersContext<'a> {
|
||||
// let param_map = params
|
||||
// .iter()
|
||||
// .map(|pair: &KVPair<'a>| (pair.key, &pair.value))
|
||||
// .collect();
|
||||
// ParametersContext {
|
||||
// params: param_map,
|
||||
// breadcrumbs: breadcrumbs,
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
impl<'a> ContextElement for ParametersContext<'a> {}
|
||||
// impl<'a> ContextElement for ParametersContext<'a> {}
|
||||
|
||||
impl<'a> Renderable for ParametersContext<'a> {
|
||||
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<'a> Renderable for ParametersContext<'a> {
|
||||
// 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<'a> Loopable for ParametersContext<'a> {
|
||||
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<'a> Loopable for ParametersContext<'a> {
|
||||
// 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<'a> Walkable for ParametersContext<'a> {
|
||||
fn walk(&self, segment: &str) -> Result<&dyn ContextElement, WalkError> {
|
||||
let rval = self.params.get(segment).ok_or(WalkError::CantWalk)?;
|
||||
match rval {
|
||||
RValue::RVPath(path) => walk_path(self.breadcrumbs, &path.keys),
|
||||
RValue::RVString(text) => Ok(text),
|
||||
}
|
||||
}
|
||||
}
|
||||
// impl<'a> Walkable for ParametersContext<'a> {
|
||||
// fn walk(&self, segment: &str) -> Result<&dyn ContextElement, WalkError> {
|
||||
// let rval = self.params.get(segment).ok_or(WalkError::CantWalk)?;
|
||||
// match rval {
|
||||
// RValue::RVPath(path) => walk_path(self.breadcrumbs, &path.keys),
|
||||
// RValue::RVString(text) => Ok(text),
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
impl ContextElement for String {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user