From 39c579171b8f934e0e84b9dc2dadc2c232645e9e Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sun, 24 May 2020 15:21:30 -0400 Subject: [PATCH] Rename the new functions to replace the old functions. --- src/renderer/parameters_context.rs | 4 ++-- src/renderer/renderer.rs | 18 +++++++++--------- src/renderer/walking.rs | 8 ++++---- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/renderer/parameters_context.rs b/src/renderer/parameters_context.rs index 45d5151..92ee3b1 100644 --- a/src/renderer/parameters_context.rs +++ b/src/renderer/parameters_context.rs @@ -2,7 +2,7 @@ use crate::parser::KVPair; use crate::parser::{Filter, OwnedLiteral, RValue}; use crate::renderer::context_element::CompareContextElement; 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::RenderError; use crate::renderer::Renderable; @@ -89,7 +89,7 @@ impl Walkable for ParametersContext { fn walk(&self, segment: &str) -> Result<&dyn ContextElement, WalkError> { let rval = self.params.get(segment).ok_or(WalkError::CantWalk)?; 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), } } diff --git a/src/renderer/renderer.rs b/src/renderer/renderer.rs index d1d3a20..03ff2f4 100644 --- a/src/renderer/renderer.rs +++ b/src/renderer/renderer.rs @@ -14,7 +14,7 @@ use crate::renderer::errors::WalkError; use crate::renderer::inline_partial_tree::extract_inline_partials; use crate::renderer::inline_partial_tree::InlinePartialTreeElement; use crate::renderer::parameters_context::ParametersContext; -use crate::renderer::walking::walk_path_combined; +use crate::renderer::walking::walk_path; use std::collections::HashMap; #[derive(Clone, Debug)] @@ -146,7 +146,7 @@ impl<'a> DustRenderer<'a> { } DustTag::DTLiteralStringBlock(literal) => return Ok((*literal).to_owned()), DustTag::DTReference(reference) => { - let val = walk_path_combined(breadcrumbs, &reference.path.keys); + let val = walk_path(breadcrumbs, &reference.path.keys); match val { Err(WalkError::CantWalk) => return Ok("".to_owned()), Ok(final_val) => { @@ -160,7 +160,7 @@ impl<'a> DustRenderer<'a> { } } 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); if loop_elements.is_empty() { // Oddly enough if the value is falsey (like @@ -187,7 +187,7 @@ impl<'a> DustRenderer<'a> { } } 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); return if loop_elements.is_empty() { self.render_maybe_body(&container.else_contents, breadcrumbs, blocks) @@ -196,7 +196,7 @@ impl<'a> DustRenderer<'a> { }; } 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); return if !loop_elements.is_empty() { self.render_maybe_body(&container.else_contents, breadcrumbs, blocks) @@ -497,7 +497,7 @@ impl<'a> DustRenderer<'a> { None => None, Some(rval) => match rval { 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(); assert_eq!( - walk_path_combined(&vec![&context as &dyn ContextElement], &vec!["cat"]) + walk_path(&vec![&context as &dyn ContextElement], &vec!["cat"]) .unwrap() .render(&Vec::new()) .unwrap(), "kitty".to_owned() ); assert_eq!( - walk_path_combined( + walk_path( &vec![&number_context as &dyn ContextElement], &vec!["tiger"] ) @@ -699,7 +699,7 @@ mod tests { "3".to_owned() ); assert_eq!( - walk_path_combined( + walk_path( &vec![&deep_context as &dyn ContextElement], &vec!["tiger", "food"] ) diff --git a/src/renderer/walking.rs b/src/renderer/walking.rs index ae24dde..5a38458 100644 --- a/src/renderer/walking.rs +++ b/src/renderer/walking.rs @@ -8,7 +8,7 @@ enum WalkResult<'a> { 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 P: Borrow, C: Borrow, @@ -34,7 +34,7 @@ where WalkResult::FullyWalked(output) } -pub fn walk_path_combined<'a, B, P>( +pub fn walk_path<'a, B, P>( breadcrumbs: &'a Vec, path: &Vec

, ) -> Result<&'a dyn ContextElement, WalkError> @@ -54,7 +54,7 @@ where .borrow() == "." { - return match walk_path_from_single_level_borrow( + return match walk_path_from_single_level( breadcrumbs .last() .expect("Breadcrumbs should never be empty"), @@ -68,7 +68,7 @@ where }; } 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 WalkResult::NoWalk => {} // If we partially walked then stop trying to find