Implement function to convert IceResult into a BreadcrumbTreeElement.

This commit is contained in:
Tom Alexander 2020-06-06 18:37:35 -04:00
parent 18c1687064
commit 7253c7d99e
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
2 changed files with 34 additions and 3 deletions

View File

@ -1,3 +1,4 @@
use crate::renderer::context_element::IceResult;
use crate::renderer::context_element::IntoContextElement; use crate::renderer::context_element::IntoContextElement;
use std::borrow::Borrow; use std::borrow::Borrow;
use std::rc::Rc; use std::rc::Rc;
@ -17,6 +18,17 @@ pub enum BreadcrumbTreeElement<'a> {
Borrowed(&'a dyn IntoContextElement), Borrowed(&'a dyn IntoContextElement),
} }
impl<'a> From<&'a IceResult<'a>> for BreadcrumbTreeElement<'a> {
fn from(inp: &'a IceResult<'a>) -> Self {
match inp {
IceResult::Owned(rc_ce) => {
BreadcrumbTreeElement::Borrowed(rc_ce.from_context_element())
}
IceResult::Borrowed(ce) => BreadcrumbTreeElement::Borrowed(ce.from_context_element()),
}
}
}
impl<'a> BreadcrumbTree<'a> { impl<'a> BreadcrumbTree<'a> {
pub fn new(parent: Option<&'a BreadcrumbTree>, element: BreadcrumbTreeElement<'a>) -> Self { pub fn new(parent: Option<&'a BreadcrumbTree>, element: BreadcrumbTreeElement<'a>) -> Self {
BreadcrumbTree { BreadcrumbTree {

View File

@ -27,8 +27,8 @@ pub struct ParametersContext<'a> {
impl<'a> ParametersContext<'a> { impl<'a> ParametersContext<'a> {
pub fn new( pub fn new(
renderer: &DustRenderer, renderer: &DustRenderer,
breadcrumbs: Option<&BreadcrumbTree>, breadcrumbs: Option<&'a BreadcrumbTree>,
params: &Vec<KVPair>, params: &'a Vec<KVPair>,
) -> Self { ) -> Self {
// If the parameter is a Path, then we resolve it immediately // If the parameter is a Path, then we resolve it immediately
// to a context element because those are resolved using the // to a context element because those are resolved using the
@ -38,8 +38,27 @@ impl<'a> ParametersContext<'a> {
// then those are resolved at the time of access rather than // then those are resolved at the time of access rather than
// the time of assignment, so we leave them into their // the time of assignment, so we leave them into their
// original IntoContextElement state. // original IntoContextElement state.
let rendered_params = params
.iter()
.map(|kvpair| {
let k = kvpair.key;
let v: &dyn IntoContextElement = match &kvpair.value {
RValue::RVLiteral(owned_literal) => &kvpair.value,
/*RValue::RVPath(path) => kvpair
.value
.into_context_element(renderer, breadcrumbs)
.unwrap()
.get_context_element_reference()
.from_context_element(),*/
RValue::RVPath(path) => todo!(),
RValue::RVTemplate(template) => todo!(),
};
(k, v)
})
.collect();
ParametersContext { ParametersContext {
params: HashMap::new(), params: rendered_params,
} }
} }
} }