Going extreme: removing all fields and unifying all walk errors.

This commit is contained in:
Tom Alexander 2020-05-09 14:00:19 -04:00
parent b20368c586
commit fcb2f3fc4d
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
3 changed files with 6 additions and 11 deletions

View File

@ -1,11 +1,12 @@
use crate::parser::Filter; use crate::parser::Filter;
use crate::renderer::errors::RenderError; use crate::renderer::errors::RenderError;
use crate::renderer::errors::WalkError;
use std::fmt::Debug; use std::fmt::Debug;
pub trait ContextElement: Debug + Walkable + Renderable + Loopable {} pub trait ContextElement: Debug + Walkable + Renderable + Loopable {}
pub trait Walkable { pub trait Walkable {
fn walk(&self, segment: &str) -> Result<&dyn ContextElement, RenderError>; fn walk(&self, segment: &str) -> Result<&dyn ContextElement, WalkError>;
} }
pub trait Renderable { pub trait Renderable {

View File

@ -15,15 +15,8 @@ pub enum RenderError<'a> {
}, },
} }
pub enum WalkError<'a> { pub enum WalkError {
CantWalk { CantWalk,
segment: String,
elem: &'a dyn ContextElement,
},
NotFound {
path: &'a Vec<&'a str>,
breadcrumbs: Vec<&'a dyn ContextElement>,
},
} }
#[derive(Clone)] #[derive(Clone)]

View File

@ -7,6 +7,7 @@ use crate::parser::TemplateElement;
use crate::renderer::context_element::ContextElement; use crate::renderer::context_element::ContextElement;
use crate::renderer::errors::CompileError; use crate::renderer::errors::CompileError;
use crate::renderer::errors::RenderError; use crate::renderer::errors::RenderError;
use crate::renderer::errors::WalkError;
use crate::renderer::parameters_context::ParametersContext; use crate::renderer::parameters_context::ParametersContext;
use std::collections::HashMap; use std::collections::HashMap;
@ -226,7 +227,7 @@ fn walk_path_from_single_level<'a>(
let mut output = context; let mut output = context;
for elem in path.iter() { for elem in path.iter() {
let new_val = output.walk(elem); let new_val = output.walk(elem);
if let Err(RenderError::CantWalk { .. }) = new_val { if let Err(WalkError::CantWalk { .. }) = new_val {
return Ok(walk_failure); return Ok(walk_failure);
} }
walk_failure = WalkResult::PartialWalk; walk_failure = WalkResult::PartialWalk;