Rename the new functions to replace the old functions.

This commit is contained in:
Tom Alexander 2020-05-24 15:21:30 -04:00
parent 46fe1f5204
commit 39c579171b
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
3 changed files with 15 additions and 15 deletions

View File

@ -2,7 +2,7 @@ use crate::parser::KVPair;
use crate::parser::{Filter, OwnedLiteral, RValue}; use crate::parser::{Filter, OwnedLiteral, RValue};
use crate::renderer::context_element::CompareContextElement; use crate::renderer::context_element::CompareContextElement;
use crate::renderer::context_element::ContextElement; use crate::renderer::context_element::ContextElement;
use crate::renderer::walking::walk_path_combined; use crate::renderer::walking::walk_path;
use crate::renderer::Loopable; use crate::renderer::Loopable;
use crate::renderer::RenderError; use crate::renderer::RenderError;
use crate::renderer::Renderable; use crate::renderer::Renderable;
@ -89,7 +89,7 @@ impl Walkable for ParametersContext {
fn walk(&self, segment: &str) -> Result<&dyn ContextElement, WalkError> { fn walk(&self, segment: &str) -> Result<&dyn ContextElement, WalkError> {
let rval = self.params.get(segment).ok_or(WalkError::CantWalk)?; let rval = self.params.get(segment).ok_or(WalkError::CantWalk)?;
match rval { match rval {
OwnedRValue::RVPath(path) => walk_path_combined(&self.breadcrumbs, &path.keys), OwnedRValue::RVPath(path) => walk_path(&self.breadcrumbs, &path.keys),
OwnedRValue::RVLiteral(literal) => Ok(literal), OwnedRValue::RVLiteral(literal) => Ok(literal),
} }
} }

View File

@ -14,7 +14,7 @@ use crate::renderer::errors::WalkError;
use crate::renderer::inline_partial_tree::extract_inline_partials; use crate::renderer::inline_partial_tree::extract_inline_partials;
use crate::renderer::inline_partial_tree::InlinePartialTreeElement; use crate::renderer::inline_partial_tree::InlinePartialTreeElement;
use crate::renderer::parameters_context::ParametersContext; use crate::renderer::parameters_context::ParametersContext;
use crate::renderer::walking::walk_path_combined; use crate::renderer::walking::walk_path;
use std::collections::HashMap; use std::collections::HashMap;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
@ -146,7 +146,7 @@ impl<'a> DustRenderer<'a> {
} }
DustTag::DTLiteralStringBlock(literal) => return Ok((*literal).to_owned()), DustTag::DTLiteralStringBlock(literal) => return Ok((*literal).to_owned()),
DustTag::DTReference(reference) => { DustTag::DTReference(reference) => {
let val = walk_path_combined(breadcrumbs, &reference.path.keys); let val = walk_path(breadcrumbs, &reference.path.keys);
match val { match val {
Err(WalkError::CantWalk) => return Ok("".to_owned()), Err(WalkError::CantWalk) => return Ok("".to_owned()),
Ok(final_val) => { Ok(final_val) => {
@ -160,7 +160,7 @@ impl<'a> DustRenderer<'a> {
} }
} }
DustTag::DTSection(container) => { DustTag::DTSection(container) => {
let val = walk_path_combined(breadcrumbs, &container.path.keys); let val = walk_path(breadcrumbs, &container.path.keys);
let loop_elements: Vec<&dyn ContextElement> = Self::get_loop_elements(val); let loop_elements: Vec<&dyn ContextElement> = Self::get_loop_elements(val);
if loop_elements.is_empty() { if loop_elements.is_empty() {
// Oddly enough if the value is falsey (like // Oddly enough if the value is falsey (like
@ -187,7 +187,7 @@ impl<'a> DustRenderer<'a> {
} }
} }
DustTag::DTExists(container) => { DustTag::DTExists(container) => {
let val = walk_path_combined(breadcrumbs, &container.path.keys); let val = walk_path(breadcrumbs, &container.path.keys);
let loop_elements: Vec<&dyn ContextElement> = Self::get_loop_elements(val); let loop_elements: Vec<&dyn ContextElement> = Self::get_loop_elements(val);
return if loop_elements.is_empty() { return if loop_elements.is_empty() {
self.render_maybe_body(&container.else_contents, breadcrumbs, blocks) self.render_maybe_body(&container.else_contents, breadcrumbs, blocks)
@ -196,7 +196,7 @@ impl<'a> DustRenderer<'a> {
}; };
} }
DustTag::DTNotExists(container) => { DustTag::DTNotExists(container) => {
let val = walk_path_combined(breadcrumbs, &container.path.keys); let val = walk_path(breadcrumbs, &container.path.keys);
let loop_elements: Vec<&dyn ContextElement> = Self::get_loop_elements(val); let loop_elements: Vec<&dyn ContextElement> = Self::get_loop_elements(val);
return if !loop_elements.is_empty() { return if !loop_elements.is_empty() {
self.render_maybe_body(&container.else_contents, breadcrumbs, blocks) self.render_maybe_body(&container.else_contents, breadcrumbs, blocks)
@ -497,7 +497,7 @@ impl<'a> DustRenderer<'a> {
None => None, None => None,
Some(rval) => match rval { Some(rval) => match rval {
RValue::RVLiteral(literal) => Some(Ok(literal)), RValue::RVLiteral(literal) => Some(Ok(literal)),
RValue::RVPath(path) => Some(walk_path_combined(breadcrumbs, &path.keys)), RValue::RVPath(path) => Some(walk_path(breadcrumbs, &path.keys)),
}, },
} }
} }
@ -682,14 +682,14 @@ mod tests {
.collect(); .collect();
assert_eq!( assert_eq!(
walk_path_combined(&vec![&context as &dyn ContextElement], &vec!["cat"]) walk_path(&vec![&context as &dyn ContextElement], &vec!["cat"])
.unwrap() .unwrap()
.render(&Vec::new()) .render(&Vec::new())
.unwrap(), .unwrap(),
"kitty".to_owned() "kitty".to_owned()
); );
assert_eq!( assert_eq!(
walk_path_combined( walk_path(
&vec![&number_context as &dyn ContextElement], &vec![&number_context as &dyn ContextElement],
&vec!["tiger"] &vec!["tiger"]
) )
@ -699,7 +699,7 @@ mod tests {
"3".to_owned() "3".to_owned()
); );
assert_eq!( assert_eq!(
walk_path_combined( walk_path(
&vec![&deep_context as &dyn ContextElement], &vec![&deep_context as &dyn ContextElement],
&vec!["tiger", "food"] &vec!["tiger", "food"]
) )

View File

@ -8,7 +8,7 @@ enum WalkResult<'a> {
FullyWalked(&'a dyn ContextElement), FullyWalked(&'a dyn ContextElement),
} }
fn walk_path_from_single_level_borrow<'a, P, C>(context: &'a C, path: &[P]) -> WalkResult<'a> fn walk_path_from_single_level<'a, P, C>(context: &'a C, path: &[P]) -> WalkResult<'a>
where where
P: Borrow<str>, P: Borrow<str>,
C: Borrow<dyn ContextElement + 'a>, C: Borrow<dyn ContextElement + 'a>,
@ -34,7 +34,7 @@ where
WalkResult::FullyWalked(output) WalkResult::FullyWalked(output)
} }
pub fn walk_path_combined<'a, B, P>( pub fn walk_path<'a, B, P>(
breadcrumbs: &'a Vec<B>, breadcrumbs: &'a Vec<B>,
path: &Vec<P>, path: &Vec<P>,
) -> Result<&'a dyn ContextElement, WalkError> ) -> Result<&'a dyn ContextElement, WalkError>
@ -54,7 +54,7 @@ where
.borrow() .borrow()
== "." == "."
{ {
return match walk_path_from_single_level_borrow( return match walk_path_from_single_level(
breadcrumbs breadcrumbs
.last() .last()
.expect("Breadcrumbs should never be empty"), .expect("Breadcrumbs should never be empty"),
@ -68,7 +68,7 @@ where
}; };
} }
for context in breadcrumbs.iter().rev() { for context in breadcrumbs.iter().rev() {
match walk_path_from_single_level_borrow(context, path) { match walk_path_from_single_level(context, path) {
// If no walking was done at all, keep looping // If no walking was done at all, keep looping
WalkResult::NoWalk => {} WalkResult::NoWalk => {}
// If we partially walked then stop trying to find // If we partially walked then stop trying to find