Implemented owned_walk_path.

This commit is contained in:
Tom Alexander 2020-05-10 21:38:37 -04:00
parent dade738f55
commit 798d84828e
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
1 changed files with 14 additions and 2 deletions

View File

@ -53,9 +53,21 @@ pub fn walk_path<'a>(
}
pub fn owned_walk_path<'a>(
breadcrumbs: &Vec<Box<dyn ContextElement>>,
breadcrumbs: &'a Vec<Box<dyn ContextElement>>,
path: &Vec<String>,
) -> 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)
}