I think its working

This commit is contained in:
Tom Alexander 2020-04-11 22:23:59 -04:00
parent 5efa650b67
commit 47bb055b67
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
2 changed files with 7 additions and 20 deletions

View File

@ -139,30 +139,18 @@ mod tests {
fn walk(&self, segment: &str) -> &dyn ContextElement {
self.get(segment).unwrap()
}
fn val(&self) -> String {
"val".to_owned()
}
}
impl Walkable for &str {
fn walk(&self, segment: &str) -> &dyn ContextElement {
panic!("Tried to walk down a str");
}
fn val(&self) -> String {
"val".to_owned()
}
}
impl Walkable for u32 {
fn walk(&self, segment: &str) -> &dyn ContextElement {
panic!("Tried to walk down a str");
}
fn val(&self) -> String {
"val".to_owned()
}
}
fn do_the_walk<'a>(
@ -172,7 +160,7 @@ mod tests {
let mut output = context;
for elem in path.iter() {
output = context.walk(elem);
output = output.walk(elem);
}
output
@ -199,9 +187,9 @@ mod tests {
.collect();
assert_eq!(do_the_walk(&context, &vec!["cat"]).render(), "kitty");
assert_eq!(do_the_walk(&number_context, &vec!["tiger"]).render(), "3");
// assert_eq!(
// do_the_walk(&deep_context, &vec!["tiger", "food"]).render(),
// "people"
// );
assert_eq!(
do_the_walk(&deep_context, &vec!["tiger", "food"]).render(),
"people"
);
}
}

View File

@ -1,9 +1,8 @@
use super::renderable::Renderable;
use std::fmt::Debug;
pub trait ContextElement: Walkable + Renderable {}
pub trait ContextElement: Walkable + Renderable + Debug {}
pub trait Walkable {
fn walk(&self, segment: &str) -> &dyn ContextElement;
fn val(&self) -> String;
}