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

@@ -16,6 +16,7 @@ pub trait ContextElement:
// + CloneIntoBoxedContextElement
+ CompareContextElement
+ FromContextElement
+ IntoRcIce
{
}
@@ -119,6 +120,16 @@ impl<C: ContextElement> IntoContextElement for C {
}
}
pub trait IntoRcIce {
fn into_rc_ice(self: Rc<Self>) -> Rc<dyn IntoContextElement>;
}
impl<C: 'static + ContextElement> IntoRcIce for C {
fn into_rc_ice(self: Rc<C>) -> Rc<dyn IntoContextElement> {
Rc::clone(&self) as Rc<dyn IntoContextElement>
}
}
#[derive(Clone, Debug)]
pub enum IceResult<'a> {
// Using Rc so that when we need to create BreadcrumbTrees with