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 {
|
impl<'a> Walkable for u32 {
|
||||||
type Output = 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)
|
c.walk(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_walk_path() {
|
fn test_walk_path() {
|
||||||
let context: HashMap<&str, u32> = [("cat", 1), ("dog", 2), ("tiger", 3)]
|
let context: HashMap<&str, &str> =
|
||||||
|
[("cat", "kitty"), ("dog", "doggy"), ("tiger", "murderkitty")]
|
||||||
.iter()
|
.iter()
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect();
|
.collect();
|
||||||
assert_eq!(do_the_walk(&context, "cat"), &1);
|
assert_eq!(do_the_walk(&context, "cat"), "kitty");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user