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::CompileError;
|
||||||
use crate::renderer::errors::RenderError;
|
use crate::renderer::errors::RenderError;
|
||||||
use crate::renderer::renderable::Renderable;
|
use crate::renderer::renderable::Renderable;
|
||||||
|
use crate::renderer::walkable::ContextElement;
|
||||||
use crate::renderer::walkable::Walkable;
|
use crate::renderer::walkable::Walkable;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::ops::Index;
|
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
|
fn walk_path<'a>(context: &'a dyn ContextElement, path: &Vec<&str>) -> &'a dyn ContextElement {
|
||||||
// where
|
let mut output = context;
|
||||||
// C: Walkable<Output = C>,
|
|
||||||
// {
|
|
||||||
// let mut output: &C = context;
|
|
||||||
|
|
||||||
// for elem in path.iter() {
|
for elem in path.iter() {
|
||||||
// output = context.walk(elem);
|
output = output.walk(elem);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// output
|
output
|
||||||
// }
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::renderer::walkable::ContextElement;
|
|
||||||
|
|
||||||
impl ContextElement for u32 {}
|
impl ContextElement for u32 {}
|
||||||
impl ContextElement for &str {}
|
impl ContextElement for &str {}
|
||||||
@ -142,30 +139,17 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Walkable for &str {
|
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");
|
panic!("Tried to walk down a str");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Walkable for u32 {
|
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");
|
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]
|
#[test]
|
||||||
fn test_walk_path() {
|
fn test_walk_path() {
|
||||||
let context: HashMap<&str, &str> =
|
let context: HashMap<&str, &str> =
|
||||||
@ -185,10 +169,10 @@ mod tests {
|
|||||||
.iter()
|
.iter()
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect();
|
.collect();
|
||||||
assert_eq!(do_the_walk(&context, &vec!["cat"]).render(), "kitty");
|
assert_eq!(walk_path(&context, &vec!["cat"]).render(), "kitty");
|
||||||
assert_eq!(do_the_walk(&number_context, &vec!["tiger"]).render(), "3");
|
assert_eq!(walk_path(&number_context, &vec!["tiger"]).render(), "3");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
do_the_walk(&deep_context, &vec!["tiger", "food"]).render(),
|
walk_path(&deep_context, &vec!["tiger", "food"]).render(),
|
||||||
"people"
|
"people"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user