Going to try switching to boxed owned values to remove the template.
This commit is contained in:
parent
92dca74505
commit
2b532e7eb4
@ -7,17 +7,17 @@ pub trait BreadcrumbTree {
|
||||
fn get_parent(&self) -> Option<&dyn BreadcrumbTree>;
|
||||
}
|
||||
|
||||
pub struct BreadcrumbTreeNode<'a, C: IntoContextElement> {
|
||||
pub struct BreadcrumbTreeNode<'a> {
|
||||
parent: Option<&'a dyn BreadcrumbTree>,
|
||||
element: BreadcrumbTreeNodeElement<'a, C>,
|
||||
element: BreadcrumbTreeNodeElement<'a>,
|
||||
}
|
||||
|
||||
pub enum BreadcrumbTreeNodeElement<'a, C: IntoContextElement> {
|
||||
Owned(C),
|
||||
Borrowed(&'a C),
|
||||
pub enum BreadcrumbTreeNodeElement<'a> {
|
||||
Owned(Box<dyn IntoContextElement>),
|
||||
Borrowed(&'a dyn IntoContextElement),
|
||||
}
|
||||
|
||||
impl<'a, C: IntoContextElement> BreadcrumbTreeNode<'a, C> {
|
||||
impl<'a> BreadcrumbTreeNode<'a> {
|
||||
pub fn ice_iter(&'a self) -> impl Iterator<Item = &dyn IntoContextElement> {
|
||||
self.breadcrumb_iter().map(|b| b.get_ice())
|
||||
}
|
||||
@ -27,18 +27,16 @@ impl<'a, C: IntoContextElement> BreadcrumbTreeNode<'a, C> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, C: IntoContextElement> Borrow<dyn IntoContextElement + 'a>
|
||||
for BreadcrumbTreeNodeElement<'a, C>
|
||||
{
|
||||
impl<'a> Borrow<dyn IntoContextElement + 'a> for BreadcrumbTreeNodeElement<'a> {
|
||||
fn borrow(&self) -> &(dyn IntoContextElement + 'a) {
|
||||
match self {
|
||||
BreadcrumbTreeNodeElement::Owned(ice) => ice,
|
||||
BreadcrumbTreeNodeElement::Owned(ice) => ice.as_ref(),
|
||||
BreadcrumbTreeNodeElement::Borrowed(ice) => *ice,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, C: IntoContextElement> BreadcrumbTree for BreadcrumbTreeNode<'a, C> {
|
||||
impl<'a> BreadcrumbTree for BreadcrumbTreeNode<'a> {
|
||||
fn get_ice(&self) -> &dyn IntoContextElement {
|
||||
self.element.borrow()
|
||||
}
|
||||
@ -48,7 +46,7 @@ impl<'a, C: IntoContextElement> BreadcrumbTree for BreadcrumbTreeNode<'a, C> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, C: IntoContextElement> IntoIterator for &'a BreadcrumbTreeNode<'a, C> {
|
||||
impl<'a> IntoIterator for &'a BreadcrumbTreeNode<'a> {
|
||||
type Item = &'a dyn BreadcrumbTree;
|
||||
type IntoIter = BreadcrumbTreeIterator<'a>;
|
||||
|
||||
|
@ -44,44 +44,44 @@ impl<'a> DustRenderer<'a> {
|
||||
.insert(template.name.clone(), &template.template);
|
||||
}
|
||||
|
||||
fn new_breadcrumbs_section<'b, B>(
|
||||
&self,
|
||||
maybe_breadcrumbs: Option<&'a BreadcrumbTreeNode<B>>,
|
||||
index_context: Option<&'b dyn IntoContextElement>,
|
||||
injected_context: Option<&'b dyn IntoContextElement>,
|
||||
explicit_context: &Option<Path<'b>>,
|
||||
new_context_element: Option<&'b dyn ContextElement>,
|
||||
) -> Option<&'a BreadcrumbTreeNode<B>>
|
||||
where
|
||||
B: IntoContextElement,
|
||||
{
|
||||
// If there is no new content, return the original breadcrumbs
|
||||
match (
|
||||
index_context,
|
||||
injected_context,
|
||||
explicit_context,
|
||||
new_context_element,
|
||||
) {
|
||||
(None, None, None, None) => return maybe_breadcrumbs,
|
||||
_ => (),
|
||||
}
|
||||
// fn new_breadcrumbs_section<'b, B>(
|
||||
// &self,
|
||||
// maybe_breadcrumbs: Option<&'a BreadcrumbTreeNode<B>>,
|
||||
// index_context: Option<&'b dyn IntoContextElement>,
|
||||
// injected_context: Option<&'b dyn IntoContextElement>,
|
||||
// explicit_context: &Option<Path<'b>>,
|
||||
// new_context_element: Option<&'b dyn ContextElement>,
|
||||
// ) -> Option<&'a BreadcrumbTreeNode<B>>
|
||||
// where
|
||||
// B: IntoContextElement,
|
||||
// {
|
||||
// // If there is no new content, return the original breadcrumbs
|
||||
// match (
|
||||
// index_context,
|
||||
// injected_context,
|
||||
// explicit_context,
|
||||
// new_context_element,
|
||||
// ) {
|
||||
// (None, None, None, None) => return maybe_breadcrumbs,
|
||||
// _ => (),
|
||||
// }
|
||||
|
||||
// If there is an explicit context, then drop all the current
|
||||
// context
|
||||
let mut new_stack = match explicit_context {
|
||||
Some(_) => None,
|
||||
None => maybe_breadcrumbs,
|
||||
};
|
||||
// // If there is an explicit context, then drop all the current
|
||||
// // context
|
||||
// let mut new_stack = match explicit_context {
|
||||
// Some(_) => None,
|
||||
// None => maybe_breadcrumbs,
|
||||
// };
|
||||
|
||||
// TODO: Explicit context
|
||||
injected_context.map(|ctx| {
|
||||
new_stack = Some(BreadcrumbTreeNode {
|
||||
parent: new_stack.map(|b| b as _),
|
||||
element: BreadcrumbTreeNodeElement::Borrowed(ctx),
|
||||
});
|
||||
// TODO
|
||||
});
|
||||
// // TODO: Explicit context
|
||||
// // injected_context.map(|ctx| {
|
||||
// // new_stack = Some(BreadcrumbTreeNode {
|
||||
// // parent: new_stack.map(|b| b as _),
|
||||
// // element: BreadcrumbTreeNodeElement::Borrowed(ctx),
|
||||
// // });
|
||||
// // // TODO
|
||||
// // });
|
||||
|
||||
None
|
||||
}
|
||||
// None
|
||||
// }
|
||||
}
|
||||
|
@ -38,24 +38,20 @@ where
|
||||
WalkResult::FullyWalked(output)
|
||||
}
|
||||
|
||||
fn get_first_non_pseudo_element<'a, B>(
|
||||
breadcrumbs: &'a BreadcrumbTreeNode<B>,
|
||||
) -> Option<&'a dyn BreadcrumbTree>
|
||||
where
|
||||
B: IntoContextElement,
|
||||
{
|
||||
fn get_first_non_pseudo_element<'a>(
|
||||
breadcrumbs: &'a BreadcrumbTreeNode,
|
||||
) -> Option<&'a dyn BreadcrumbTree> {
|
||||
breadcrumbs
|
||||
.breadcrumb_iter()
|
||||
.filter(|b| b.get_ice().is_pseudo_element())
|
||||
.next()
|
||||
}
|
||||
|
||||
pub fn walk_path<'a, B, P>(
|
||||
maybe_breadcrumbs: Option<&'a BreadcrumbTreeNode<B>>,
|
||||
pub fn walk_path<'a, P>(
|
||||
maybe_breadcrumbs: Option<&'a BreadcrumbTreeNode>,
|
||||
path: &Vec<P>,
|
||||
) -> Result<&'a dyn IntoContextElement, WalkError>
|
||||
where
|
||||
B: IntoContextElement,
|
||||
P: Borrow<str>,
|
||||
{
|
||||
match (maybe_breadcrumbs, path.first()) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user