diff --git a/src/renderer/renderer.rs b/src/renderer/renderer.rs index b82e683..07c5147 100644 --- a/src/renderer/renderer.rs +++ b/src/renderer/renderer.rs @@ -163,9 +163,15 @@ impl<'a> DustRenderer<'a> { let val = walk_path(breadcrumbs, &container.path.keys); match val { Err(WalkError::CantWalk) => { + let new_breadcrumbs = Self::new_breadcrumbs( + breadcrumbs, + None, + &container.explicit_context, + None, + ); return self.render_maybe_body( &container.else_contents, - breadcrumbs, + new_breadcrumbs.as_ref().unwrap_or(breadcrumbs), blocks, ); } @@ -591,7 +597,14 @@ impl<'a> DustRenderer<'a> { injected_context: Option<&'b dyn ContextElement>, explicit_context: &Option>, new_context_element: Option<&'b dyn ContextElement>, - ) -> Vec<&'b dyn ContextElement> { + ) -> Option> { + // If none of the additional contexts are present, return None + // to signal that the original breadcrumbs should be used + // rather than incurring a copy here. + match (injected_context, explicit_context, new_context_element) { + (None, None, None) => return None, + _ => (), + }; let mut new_stack = match explicit_context { Some(_) => Vec::with_capacity(3), None => breadcrumbs.clone(), @@ -605,7 +618,7 @@ impl<'a> DustRenderer<'a> { }); }); new_context_element.map(|ctx| new_stack.push(ctx)); - new_stack + Some(new_stack) } }