From 7d63d6ef7b540d6909c531cdf745f88c5efbb7b3 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 9 May 2020 13:51:02 -0400 Subject: [PATCH] Merge Cant and Wont Walk. --- src/bin.rs | 2 +- src/renderer/errors.rs | 13 +------------ src/renderer/renderer.rs | 6 ++---- 3 files changed, 4 insertions(+), 17 deletions(-) diff --git a/src/bin.rs b/src/bin.rs index bb1c1f1..6c314a3 100644 --- a/src/bin.rs +++ b/src/bin.rs @@ -116,7 +116,7 @@ impl Walkable for serde_json::Value { serde_json::Value::Object(obj) => { obj.get(segment) .map(|val| val as _) - .ok_or(RenderError::WontWalk { + .ok_or(RenderError::CantWalk { segment: segment.to_string(), elem: self, }) diff --git a/src/renderer/errors.rs b/src/renderer/errors.rs index 8041fc8..13f249e 100644 --- a/src/renderer/errors.rs +++ b/src/renderer/errors.rs @@ -4,13 +4,8 @@ use std::fmt; pub enum RenderError<'a> { Generic(String), - /// For when walking is absolutely impossible - CantWalk { - segment: String, - elem: &'a dyn ContextElement, - }, /// For when walking fails (example, a missing key on a map) - WontWalk { + CantWalk { segment: String, elem: &'a dyn ContextElement, }, @@ -32,9 +27,6 @@ impl fmt::Display for RenderError<'_> { RenderError::CantWalk { segment, elem } => { write!(f, "Tried to walk to {} from {:?}", segment, elem) } - RenderError::WontWalk { segment, elem } => { - write!(f, "Failed to walk to {} from {:?}", segment, elem) - } RenderError::NotFound { path, breadcrumbs } => { write!(f, "Could not find {:?} in {:?}", path, breadcrumbs) } @@ -49,9 +41,6 @@ impl fmt::Debug for RenderError<'_> { RenderError::CantWalk { segment, elem } => { write!(f, "Tried to walk to {} from {:?}", segment, elem) } - RenderError::WontWalk { segment, elem } => { - write!(f, "Failed to walk to {} from {:?}", segment, elem) - } RenderError::NotFound { path, breadcrumbs } => { write!(f, "Could not find {:?} in {:?}", path, breadcrumbs) } diff --git a/src/renderer/renderer.rs b/src/renderer/renderer.rs index 33159f3..7d2e9da 100644 --- a/src/renderer/renderer.rs +++ b/src/renderer/renderer.rs @@ -226,9 +226,7 @@ fn walk_path_from_single_level<'a>( let mut output = context; for elem in path.iter() { let new_val = output.walk(elem); - if let Err(RenderError::WontWalk { .. }) = new_val { - return Ok(walk_failure); - } else if let Err(RenderError::CantWalk { .. }) = new_val { + if let Err(RenderError::CantWalk { .. }) = new_val { return Ok(walk_failure); } walk_failure = WalkResult::PartialWalk; @@ -298,7 +296,7 @@ mod tests { impl Walkable for HashMap<&str, I> { fn walk(&self, segment: &str) -> Result<&dyn ContextElement, RenderError> { - let child = self.get(segment).ok_or(RenderError::WontWalk { + let child = self.get(segment).ok_or(RenderError::CantWalk { segment: segment.to_string(), elem: self, })?;