diff --git a/src/renderer/context_element.rs b/src/renderer/context_element.rs index 49cc72d..7a2d7f4 100644 --- a/src/renderer/context_element.rs +++ b/src/renderer/context_element.rs @@ -4,6 +4,7 @@ use crate::renderer::errors::RenderError; use crate::renderer::errors::WalkError; use crate::renderer::DustRenderer; use std::any::Any; +use std::rc::Rc; use std::{cmp::Ordering, fmt::Debug}; pub trait ContextElement: @@ -117,3 +118,41 @@ impl IntoContextElement for C { Some(self) } } + +#[derive(Clone, Debug)] +pub enum IceResult<'a> { + // Using Rc so that when we need to create BreadcrumbTrees with + // the same BreadcrumbTreeElement but a different parent (for + // example, when inserting behind the tail), we don't need to the + // copy the already owned/malloc'd data. + Owned(Rc), + Borrowed(&'a dyn ContextElement), +} + +impl<'a> IceResult<'a> { + pub fn get_context_element_reference(&self) -> &dyn ContextElement { + match self { + IceResult::Owned(rc_ce) => rc_ce.as_ref(), + IceResult::Borrowed(ce) => *ce, + } + } +} + +impl<'a> IntoContextElement for IceResult<'a> { + fn into_context_element<'b>( + &'b self, + renderer: &DustRenderer, + breadcrumbs: Option<&'b BreadcrumbTree<'b>>, + ) -> Option<&'b dyn ContextElement> { + match self { + IceResult::Owned(rc_ce) => Some(rc_ce.as_ref()), + IceResult::Borrowed(ce) => Some(*ce), + } + } +} + +impl<'a> Walkable for IceResult<'a> { + fn walk(&self, segment: &str) -> Result<&dyn IntoContextElement, WalkError> { + self.get_context_element_reference().walk(segment) + } +} diff --git a/src/renderer/parameters_context.rs b/src/renderer/parameters_context.rs index 7e86c3e..20ec150 100644 --- a/src/renderer/parameters_context.rs +++ b/src/renderer/parameters_context.rs @@ -46,12 +46,13 @@ impl<'a> IntoContextElement for RValue<'a> { .flatten(), RValue::RVTemplate(template) => { // TODO - renderer - .render_partial_name(template, breadcrumbs) - .map(|rendered| OwnedLiteral::LString(rendered)) - .ok() - .as_ref() - .map(|l| l as _) + // renderer + // .render_partial_name(template, breadcrumbs) + // .map(|rendered| OwnedLiteral::LString(rendered)) + // .ok() + // .as_ref() + // .map(|l| l as _) + todo!() } } }