|
|
|
@ -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)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|