Create from_borrowed and from_owned constructors for IceResult and BreadcrumbTreeElement.
In an effort to keep track of how often memory is getting heap allocated, I am implementing constructors for IceResult and BreadcrumbTreeElement. This should limit the places that I call Rc::new and allow me to place tracing code into it later to ensure all code paths doing heap allocation make sense.
This commit is contained in:
@@ -20,13 +20,25 @@ pub enum BreadcrumbTreeElement<'a> {
|
||||
Borrowed(&'a dyn IntoContextElement),
|
||||
}
|
||||
|
||||
impl<'a> BreadcrumbTreeElement<'a> {
|
||||
pub fn from_owned<I: 'a + IntoContextElement>(val: I) -> BreadcrumbTreeElement<'a> {
|
||||
BreadcrumbTreeElement::Owned(Rc::new(val))
|
||||
}
|
||||
|
||||
pub fn from_borrowed(val: &'a dyn IntoContextElement) -> BreadcrumbTreeElement<'a> {
|
||||
BreadcrumbTreeElement::Borrowed(val)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a IceResult<'a>> for BreadcrumbTreeElement<'a> {
|
||||
fn from(inp: &'a IceResult<'a>) -> Self {
|
||||
match inp {
|
||||
IceResult::Owned(rc_ce) => {
|
||||
BreadcrumbTreeElement::Borrowed(rc_ce.from_context_element())
|
||||
BreadcrumbTreeElement::from_borrowed(rc_ce.from_context_element())
|
||||
}
|
||||
IceResult::Borrowed(ce) => {
|
||||
BreadcrumbTreeElement::from_borrowed(ce.from_context_element())
|
||||
}
|
||||
IceResult::Borrowed(ce) => BreadcrumbTreeElement::Borrowed(ce.from_context_element()),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -35,7 +47,9 @@ 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()),
|
||||
IceResult::Borrowed(ce) => {
|
||||
BreadcrumbTreeElement::from_borrowed(ce.from_context_element())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user