Merge Cant and Wont Walk.

This commit is contained in:
Tom Alexander 2020-05-09 13:51:02 -04:00
parent 2108f5cace
commit 7d63d6ef7b
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
3 changed files with 4 additions and 17 deletions

View File

@ -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,
})

View File

@ -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)
}

View File

@ -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<I: ContextElement> 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,
})?;