Switching over to dyn Walkables
This commit is contained in:
parent
ec3276af79
commit
5098ee6338
@ -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())
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user