From 63124bc6e302fbacc1c0b642a3c1bf5e903ddf0e Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 11 Apr 2020 21:07:12 -0400 Subject: [PATCH] Adding &str --- src/renderer/renderer.rs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/renderer/renderer.rs b/src/renderer/renderer.rs index 60a7db9..724ec3e 100644 --- a/src/renderer/renderer.rs +++ b/src/renderer/renderer.rs @@ -120,6 +120,14 @@ mod tests { } } + impl<'a> Walkable for &str { + type Output = u32; + + fn walk(&self, segment: &str) -> &u32 { + panic!("Tried to walk down a str"); + } + } + impl<'a> Walkable for u32 { type Output = u32; @@ -128,16 +136,17 @@ mod tests { } } - fn do_the_walk<'a>(c: &'a (dyn Walkable + 'a), path: &str) -> &'a u32 { + fn do_the_walk<'a>(c: &'a (dyn Walkable + 'a), path: &str) -> &'a str { c.walk(path) } #[test] fn test_walk_path() { - let context: HashMap<&str, u32> = [("cat", 1), ("dog", 2), ("tiger", 3)] - .iter() - .cloned() - .collect(); - assert_eq!(do_the_walk(&context, "cat"), &1); + let context: HashMap<&str, &str> = + [("cat", "kitty"), ("dog", "doggy"), ("tiger", "murderkitty")] + .iter() + .cloned() + .collect(); + assert_eq!(do_the_walk(&context, "cat"), "kitty"); } }