From 869c32df2174d5486d31eaad5bc03b3a74c43d0f Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 11 Apr 2020 22:54:48 -0400 Subject: [PATCH] Moving the custom types for the walk_path test inside the test function --- src/renderer/renderer.rs | 80 ++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/src/renderer/renderer.rs b/src/renderer/renderer.rs index 54eb92d..977c8a3 100644 --- a/src/renderer/renderer.rs +++ b/src/renderer/renderer.rs @@ -107,48 +107,48 @@ fn walk_path<'a>(context: &'a dyn ContextElement, path: &Vec<&str>) -> &'a dyn C mod tests { use super::*; - impl ContextElement for u32 {} - impl ContextElement for &str {} - impl ContextElement for HashMap<&str, I> {} - - impl Renderable for u32 { - fn render(&self) -> std::string::String { - self.to_string() - } - } - - impl Renderable for &str { - fn render(&self) -> std::string::String { - self.to_string() - } - } - - impl Renderable for HashMap<&str, I> { - fn render(&self) -> std::string::String { - panic!("Attempted to render a hashmap"); - } - } - - impl Walkable for HashMap<&str, I> { - fn walk(&self, segment: &str) -> &dyn ContextElement { - self.get(segment).unwrap() - } - } - - impl Walkable for &str { - 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 { - panic!("Tried to walk down a str"); - } - } - #[test] fn test_walk_path() { + impl ContextElement for u32 {} + impl ContextElement for &str {} + impl ContextElement for HashMap<&str, I> {} + + impl Renderable for u32 { + fn render(&self) -> std::string::String { + self.to_string() + } + } + + impl Renderable for &str { + fn render(&self) -> std::string::String { + self.to_string() + } + } + + impl Renderable for HashMap<&str, I> { + fn render(&self) -> std::string::String { + panic!("Attempted to render a hashmap"); + } + } + + impl Walkable for HashMap<&str, I> { + fn walk(&self, segment: &str) -> &dyn ContextElement { + self.get(segment).unwrap() + } + } + + impl Walkable for &str { + 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 { + panic!("Tried to walk down a str"); + } + } + let context: HashMap<&str, &str> = [("cat", "kitty"), ("dog", "doggy"), ("tiger", "murderkitty")] .iter()