Switching over to dyn Walkables

This commit is contained in:
Tom Alexander 2020-04-11 21:57:24 -04:00
parent ec3276af79
commit 5098ee6338
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
2 changed files with 16 additions and 22 deletions

View File

@ -95,27 +95,25 @@ impl<'a> DustRenderer<'a> {
}
}
fn walk_path<'a, C>(context: &'a C, path: &Vec<&str>) -> &'a C
where
C: Walkable<Output = C>,
{
let mut output: &C = context;
// fn walk_path<'a, C>(context: &'a C, path: &Vec<&str>) -> &'a C
// where
// C: Walkable<Output = C>,
// {
// let mut output: &C = context;
for elem in path.iter() {
output = context.walk(elem);
}
// for elem in path.iter() {
// output = context.walk(elem);
// }
output
}
// output
// }
#[cfg(test)]
mod tests {
use super::*;
impl<'a, I: Walkable> Walkable for HashMap<&str, I> {
type Output = I;
fn walk(&self, segment: &str) -> &I {
fn walk(&self, segment: &str) -> &dyn Walkable {
self.get(segment).unwrap()
}
@ -125,9 +123,7 @@ mod tests {
}
impl<'a> Walkable for &str {
type Output = u32;
fn walk(&self, segment: &str) -> &u32 {
fn walk(&self, segment: &str) -> &dyn Walkable {
panic!("Tried to walk down a str");
}
@ -137,9 +133,7 @@ mod tests {
}
impl<'a> Walkable for u32 {
type Output = u32;
fn walk(&self, segment: &str) -> &u32 {
fn walk(&self, segment: &str) -> &dyn Walkable {
panic!("Tried to walk down a str");
}
@ -148,7 +142,7 @@ mod tests {
}
}
fn do_the_walk<'a>(context: &'a impl Walkable, path: &Vec<&str>) -> &'a impl Walkable {
fn do_the_walk<'a>(context: &'a impl Walkable, path: &Vec<&str>) -> &'a dyn Walkable {
let mut output = context;
context.walk(path.first().unwrap())

View File

@ -1,9 +1,9 @@
use super::renderable::Renderable;
pub trait Walkable {
type Output: Walkable;
// type Output: Walkable;
fn walk(&self, segment: &str) -> &Self::Output;
fn walk(&self, segment: &str) -> &dyn Walkable;
fn val(&self) -> String;
}