Adding &str
This commit is contained in:
		
							parent
							
								
									d296ad6b56
								
							
						
					
					
						commit
						63124bc6e3
					
				| @ -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<Output = u32> + 'a), path: &str) -> &'a u32 { | ||||
|     fn do_the_walk<'a>(c: &'a (dyn Walkable<Output = &'static str> + '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"); | ||||
|     } | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Tom Alexander
						Tom Alexander