Cleaning up
This commit is contained in:
parent
47bb055b67
commit
dbfa7ea4dc
@ -5,6 +5,7 @@ use crate::parser::TemplateElement;
|
||||
use crate::renderer::errors::CompileError;
|
||||
use crate::renderer::errors::RenderError;
|
||||
use crate::renderer::renderable::Renderable;
|
||||
use crate::renderer::walkable::ContextElement;
|
||||
use crate::renderer::walkable::Walkable;
|
||||
use std::collections::HashMap;
|
||||
use std::ops::Index;
|
||||
@ -95,23 +96,19 @@ impl<'a> DustRenderer<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
// fn walk_path<'a, C>(context: &'a C, path: &Vec<&str>) -> &'a C
|
||||
// where
|
||||
// C: Walkable<Output = C>,
|
||||
// {
|
||||
// let mut output: &C = context;
|
||||
fn walk_path<'a>(context: &'a dyn ContextElement, path: &Vec<&str>) -> &'a dyn ContextElement {
|
||||
let mut output = context;
|
||||
|
||||
// for elem in path.iter() {
|
||||
// output = context.walk(elem);
|
||||
// }
|
||||
for elem in path.iter() {
|
||||
output = output.walk(elem);
|
||||
}
|
||||
|
||||
// output
|
||||
// }
|
||||
output
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::renderer::walkable::ContextElement;
|
||||
|
||||
impl ContextElement for u32 {}
|
||||
impl ContextElement for &str {}
|
||||
@ -142,30 +139,17 @@ mod tests {
|
||||
}
|
||||
|
||||
impl Walkable for &str {
|
||||
fn walk(&self, segment: &str) -> &dyn ContextElement {
|
||||
fn walk(&self, _segment: &str) -> &dyn ContextElement {
|
||||
panic!("Tried to walk down a str");
|
||||
}
|
||||
}
|
||||
|
||||
impl Walkable for u32 {
|
||||
fn walk(&self, segment: &str) -> &dyn ContextElement {
|
||||
fn walk(&self, _segment: &str) -> &dyn ContextElement {
|
||||
panic!("Tried to walk down a str");
|
||||
}
|
||||
}
|
||||
|
||||
fn do_the_walk<'a>(
|
||||
context: &'a dyn ContextElement,
|
||||
path: &Vec<&str>,
|
||||
) -> &'a dyn ContextElement {
|
||||
let mut output = context;
|
||||
|
||||
for elem in path.iter() {
|
||||
output = output.walk(elem);
|
||||
}
|
||||
|
||||
output
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_walk_path() {
|
||||
let context: HashMap<&str, &str> =
|
||||
@ -185,10 +169,10 @@ mod tests {
|
||||
.iter()
|
||||
.cloned()
|
||||
.collect();
|
||||
assert_eq!(do_the_walk(&context, &vec!["cat"]).render(), "kitty");
|
||||
assert_eq!(do_the_walk(&number_context, &vec!["tiger"]).render(), "3");
|
||||
assert_eq!(walk_path(&context, &vec!["cat"]).render(), "kitty");
|
||||
assert_eq!(walk_path(&number_context, &vec!["tiger"]).render(), "3");
|
||||
assert_eq!(
|
||||
do_the_walk(&deep_context, &vec!["tiger", "food"]).render(),
|
||||
walk_path(&deep_context, &vec!["tiger", "food"]).render(),
|
||||
"people"
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user