Implement walking for a single segment,

This commit is contained in:
Tom Alexander 2020-05-04 23:10:35 -04:00
parent c3fe7b47af
commit 033fc9de6b
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -178,18 +178,41 @@ impl<'a> DustRenderer<'a> {
}
}
fn new_walk_path<'a>(
enum WalkResult<'a> {
NoWalk,
PartialWalk,
FullyWalked(&'a dyn ContextElement),
}
fn walk_path_from_single_level<'a>(
context: &'a dyn ContextElement,
path: &Vec<&str>,
breadcrumbs: Vec<&'a dyn ContextElement>,
) -> Result<&'a dyn ContextElement, RenderError<'a>> {
let mut output = context;
for elem in path.iter() {
output = output.walk(elem)?;
) -> Result<WalkResult<'a>, RenderError<'a>> {
if path.is_empty() {
return Ok(WalkResult::FullyWalked(context));
}
Ok(output)
let mut walk_failure = WalkResult::NoWalk;
let mut output = context;
for elem in path.iter() {
let new_val = output.walk(elem);
if let Err(RenderError::WontWalk { .. }) = new_val {
return Ok(walk_failure);
} else if let Err(RenderError::CantWalk { .. }) = new_val {
return Ok(walk_failure);
}
walk_failure = WalkResult::PartialWalk;
output = new_val?;
}
Ok(WalkResult::FullyWalked(context))
}
fn new_walk_path<'a>(
breadcrumbs: Vec<&'a dyn ContextElement>,
path: &Vec<&str>,
) -> Result<&'a dyn ContextElement, RenderError<'a>> {
Err(RenderError::Generic("temp".to_owned()))
}
// TODO: rename walk_path_from_single_level