Start of IceResult to return owned values from into_context_element.
This commit is contained in:
parent
7789e6245d
commit
da15439946
@ -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<C: ContextElement> 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<dyn ContextElement>),
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
@ -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!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user