diff --git a/src/renderer/renderer.rs b/src/renderer/renderer.rs index 5ec7a3c..60a7db9 100644 --- a/src/renderer/renderer.rs +++ b/src/renderer/renderer.rs @@ -112,32 +112,32 @@ where mod tests { use super::*; - impl<'a> Walkable for HashMap<&str, &str> { - type Output = str; + impl<'a, I: Walkable> Walkable for HashMap<&str, I> { + type Output = I; - fn walk(&self, segment: &str) -> &str { + fn walk(&self, segment: &str) -> &I { self.get(segment).unwrap() } } - impl<'a> Walkable for str { - type Output = str; + impl<'a> Walkable for u32 { + type Output = u32; - fn walk(&self, segment: &str) -> &str { + fn walk(&self, segment: &str) -> &u32 { panic!("Tried to walk down a str"); } } + fn do_the_walk<'a>(c: &'a (dyn Walkable + 'a), path: &str) -> &'a u32 { + c.walk(path) + } + #[test] fn test_walk_path() { - let context: HashMap<&str, &str> = [ - ("cat", "kitty"), - ("dog", "doggy"), - ("tiger", "murder kitty"), - ] - .iter() - .cloned() - .collect(); - assert_eq!(context.walk("cat"), "kitty"); + let context: HashMap<&str, u32> = [("cat", 1), ("dog", 2), ("tiger", 3)] + .iter() + .cloned() + .collect(); + assert_eq!(do_the_walk(&context, "cat"), &1); } }