diff --git a/src/renderer/walking.rs b/src/renderer/walking.rs index cc91047..b699254 100644 --- a/src/renderer/walking.rs +++ b/src/renderer/walking.rs @@ -9,7 +9,7 @@ enum WalkResult<'a> { fn walk_path_from_single_level<'a>( context: &'a dyn ContextElement, - path: &Vec<&str>, + path: &[&str], ) -> WalkResult<'a> { if path.is_empty() { return WalkResult::FullyWalked(context); @@ -18,7 +18,6 @@ fn walk_path_from_single_level<'a>( let mut walk_failure = WalkResult::NoWalk; let mut output = context; for elem in path.iter() { - let new_val = output.walk(elem); match output.walk(elem) { Err(WalkError::CantWalk { .. }) => { return walk_failure; @@ -37,6 +36,25 @@ pub fn walk_path<'a>( breadcrumbs: &Vec<&'a dyn ContextElement>, path: &'a Vec<&str>, ) -> Result<&'a dyn ContextElement, WalkError> { + if path.is_empty() { + return Ok(*breadcrumbs + .last() + .expect("Breadcrumbs should never be empty")); + } + if *path.first().expect("Already proved path is not empty") == "." { + return match walk_path_from_single_level( + *breadcrumbs + .last() + .expect("Breadcrumbs should never be empty"), + &path[1..], + ) { + // If no walking was done at all or we partially walked + // then stop trying to find anything because '.' restricts + // us to the current scope + WalkResult::NoWalk | WalkResult::PartialWalk => Err(WalkError::CantWalk), + WalkResult::FullyWalked(new_context) => Ok(new_context), + }; + } for context in breadcrumbs.iter().rev() { match walk_path_from_single_level(*context, path) { // If no walking was done at all, keep looping