Initial setup for a heterogenous tree of IntoContextElement.

This commit is contained in:
Tom Alexander 2020-05-31 13:52:20 -04:00
parent a578b57f12
commit 645b251f13
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
2 changed files with 40 additions and 0 deletions

View File

@ -0,0 +1,39 @@
use crate::renderer::context_element::IntoContextElement;
use std::borrow::Borrow;
pub trait BreadcrumbTree {
fn get_ice(&self) -> &dyn IntoContextElement;
fn get_parent(&self) -> Option<&dyn BreadcrumbTree>;
}
struct BreadcrumbTreeNode<'a, C: IntoContextElement> {
parent: Option<&'a dyn BreadcrumbTree>,
element: BreadcrumbTreeNodeElement<'a, C>,
}
enum BreadcrumbTreeNodeElement<'a, C: IntoContextElement> {
Owned(C),
Borrowed(&'a C),
}
impl<'a, C: IntoContextElement> Borrow<dyn IntoContextElement + 'a>
for BreadcrumbTreeNodeElement<'a, C>
{
fn borrow(&self) -> &(dyn IntoContextElement + 'a) {
match self {
BreadcrumbTreeNodeElement::Owned(ice) => ice,
BreadcrumbTreeNodeElement::Borrowed(ice) => *ice,
}
}
}
impl<'a, C: IntoContextElement> BreadcrumbTree for BreadcrumbTreeNode<'a, C> {
fn get_ice(&self) -> &dyn IntoContextElement {
self.element.borrow()
}
fn get_parent(&self) -> Option<&dyn BreadcrumbTree> {
self.parent
}
}

View File

@ -1,5 +1,6 @@
//! This module contains a renderer for a rust implementation of LinkedIn Dust
mod breadcrumb_tree;
mod context_element;
mod errors;
mod inline_partial_tree;