From 798d84828ec1506648ad766e4a179e79580109e7 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sun, 10 May 2020 21:38:37 -0400 Subject: [PATCH] Implemented owned_walk_path. --- src/renderer/walking.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/renderer/walking.rs b/src/renderer/walking.rs index 942db87..cc91047 100644 --- a/src/renderer/walking.rs +++ b/src/renderer/walking.rs @@ -53,9 +53,21 @@ pub fn walk_path<'a>( } pub fn owned_walk_path<'a>( - breadcrumbs: &Vec>, + breadcrumbs: &'a Vec>, path: &Vec, ) -> Result<&'a dyn ContextElement, WalkError> { - // TODO: Implement owned_walk_path + let path_reference: Vec<&str> = path.iter().map(|p| &p[..]).collect(); + for context in breadcrumbs.iter().rev() { + match walk_path_from_single_level(context.as_ref(), &path_reference) { + // If no walking was done at all, keep looping + WalkResult::NoWalk => {} + // If we partially walked then stop trying to find + // anything + WalkResult::PartialWalk => { + return Err(WalkError::CantWalk); + } + WalkResult::FullyWalked(new_context) => return Ok(new_context), + } + } Err(WalkError::CantWalk) }