Most of new_breadcrumbs_partial, just need to get the return working.

This commit is contained in:
Tom Alexander
2020-05-31 20:41:27 -04:00
parent 6bde22b667
commit 2b8894f9c2
2 changed files with 101 additions and 2 deletions

View File

@@ -1,13 +1,19 @@
use crate::renderer::context_element::IntoContextElement;
use std::borrow::Borrow;
use std::rc::Rc;
pub struct BreadcrumbTree<'a> {
parent: Option<&'a BreadcrumbTree<'a>>,
element: BreadcrumbTreeElement<'a>,
}
#[derive(Clone, Debug)]
pub enum BreadcrumbTreeElement<'a> {
Owned(Box<dyn IntoContextElement>),
// 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 IntoContextElement>),
Borrowed(&'a dyn IntoContextElement),
}
@@ -27,6 +33,10 @@ impl<'a> BreadcrumbTree<'a> {
self.parent
}
pub fn get_element(&self) -> &BreadcrumbTreeElement<'a> {
&self.element
}
pub fn ice_iter(&'a self) -> impl Iterator<Item = &dyn IntoContextElement> {
self.breadcrumb_iter().map(|b| b.get_ice())
}
@@ -34,6 +44,14 @@ impl<'a> BreadcrumbTree<'a> {
pub fn breadcrumb_iter(&'a self) -> BreadcrumbTreeIterator<'a> {
BreadcrumbTreeIterator(Some(self))
}
pub fn clone_to_new_parent(&self, parent: Option<&'a BreadcrumbTree>) -> Self {
// TODO: Maybe not needed anymore?
BreadcrumbTree {
parent: parent,
element: self.element.clone(),
}
}
}
impl<'a> Borrow<dyn IntoContextElement + 'a> for BreadcrumbTreeElement<'a> {