Implement conversion from IceResult into BreadcrumbTreeNode.

I believe this change will remove an extra heap allocation I was doing in the new_breadcrumbs_* functions for the explicit context by adding support for converting from Rc<dyn ContextElement> to Rc<dyn IntoContextElement> without copying the underlying data. This should allow conversion of the IceResult::Owned variant to the BreadcrumbTreeElement::Owned variant without extra copying.
This commit is contained in:
Tom Alexander
2020-06-06 19:39:44 -04:00
parent 7253c7d99e
commit f9dea70d23
4 changed files with 31 additions and 6 deletions

View File

@@ -1,5 +1,7 @@
use crate::renderer::context_element::ContextElement;
use crate::renderer::context_element::IceResult;
use crate::renderer::context_element::IntoContextElement;
use crate::renderer::context_element::IntoRcIce;
use std::borrow::Borrow;
use std::rc::Rc;
@@ -29,6 +31,15 @@ impl<'a> From<&'a IceResult<'a>> for BreadcrumbTreeElement<'a> {
}
}
impl<'a> From<IceResult<'a>> for BreadcrumbTreeElement<'a> {
fn from(inp: IceResult<'a>) -> Self {
match inp {
IceResult::Owned(rc_ce) => BreadcrumbTreeElement::Owned(rc_ce.into_rc_ice()),
IceResult::Borrowed(ce) => BreadcrumbTreeElement::Borrowed(ce.from_context_element()),
}
}
}
impl<'a> BreadcrumbTree<'a> {
pub fn new(parent: Option<&'a BreadcrumbTree>, element: BreadcrumbTreeElement<'a>) -> Self {
BreadcrumbTree {