Merge Cant and Wont Walk.
This commit is contained in:
parent
2108f5cace
commit
7d63d6ef7b
@ -116,7 +116,7 @@ impl Walkable for serde_json::Value {
|
|||||||
serde_json::Value::Object(obj) => {
|
serde_json::Value::Object(obj) => {
|
||||||
obj.get(segment)
|
obj.get(segment)
|
||||||
.map(|val| val as _)
|
.map(|val| val as _)
|
||||||
.ok_or(RenderError::WontWalk {
|
.ok_or(RenderError::CantWalk {
|
||||||
segment: segment.to_string(),
|
segment: segment.to_string(),
|
||||||
elem: self,
|
elem: self,
|
||||||
})
|
})
|
||||||
|
@ -4,13 +4,8 @@ use std::fmt;
|
|||||||
|
|
||||||
pub enum RenderError<'a> {
|
pub enum RenderError<'a> {
|
||||||
Generic(String),
|
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)
|
/// For when walking fails (example, a missing key on a map)
|
||||||
WontWalk {
|
CantWalk {
|
||||||
segment: String,
|
segment: String,
|
||||||
elem: &'a dyn ContextElement,
|
elem: &'a dyn ContextElement,
|
||||||
},
|
},
|
||||||
@ -32,9 +27,6 @@ impl fmt::Display for RenderError<'_> {
|
|||||||
RenderError::CantWalk { segment, elem } => {
|
RenderError::CantWalk { segment, elem } => {
|
||||||
write!(f, "Tried to walk to {} from {:?}", 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 } => {
|
RenderError::NotFound { path, breadcrumbs } => {
|
||||||
write!(f, "Could not find {:?} in {:?}", path, breadcrumbs)
|
write!(f, "Could not find {:?} in {:?}", path, breadcrumbs)
|
||||||
}
|
}
|
||||||
@ -49,9 +41,6 @@ impl fmt::Debug for RenderError<'_> {
|
|||||||
RenderError::CantWalk { segment, elem } => {
|
RenderError::CantWalk { segment, elem } => {
|
||||||
write!(f, "Tried to walk to {} from {:?}", 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 } => {
|
RenderError::NotFound { path, breadcrumbs } => {
|
||||||
write!(f, "Could not find {:?} in {:?}", path, breadcrumbs)
|
write!(f, "Could not find {:?} in {:?}", path, breadcrumbs)
|
||||||
}
|
}
|
||||||
|
@ -226,9 +226,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::WontWalk { .. }) = new_val {
|
if let Err(RenderError::CantWalk { .. }) = new_val {
|
||||||
return Ok(walk_failure);
|
|
||||||
} else if let Err(RenderError::CantWalk { .. }) = new_val {
|
|
||||||
return Ok(walk_failure);
|
return Ok(walk_failure);
|
||||||
}
|
}
|
||||||
walk_failure = WalkResult::PartialWalk;
|
walk_failure = WalkResult::PartialWalk;
|
||||||
@ -298,7 +296,7 @@ mod tests {
|
|||||||
|
|
||||||
impl<I: ContextElement> Walkable for HashMap<&str, I> {
|
impl<I: ContextElement> Walkable for HashMap<&str, I> {
|
||||||
fn walk(&self, segment: &str) -> Result<&dyn ContextElement, RenderError> {
|
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(),
|
segment: segment.to_string(),
|
||||||
elem: self,
|
elem: self,
|
||||||
})?;
|
})?;
|
||||||
|
Loading…
Reference in New Issue
Block a user