Initial setup for a heterogenous tree of IntoContextElement.
This commit is contained in:
parent
a578b57f12
commit
645b251f13
39
src/renderer/breadcrumb_tree.rs
Normal file
39
src/renderer/breadcrumb_tree.rs
Normal 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
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user