Finished creating WalkError.
This commit is contained in:
parent
f2f6404017
commit
05b56e83a9
@ -291,52 +291,43 @@ 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::CantWalk {
|
||||
segment: segment.to_string(),
|
||||
elem: self,
|
||||
})?;
|
||||
fn walk(&self, segment: &str) -> Result<&dyn ContextElement, WalkError> {
|
||||
let child = self.get(segment).ok_or(WalkError::CantWalk)?;
|
||||
Ok(child)
|
||||
}
|
||||
}
|
||||
|
||||
impl Walkable for &str {
|
||||
fn walk(&self, segment: &str) -> Result<&dyn ContextElement, RenderError> {
|
||||
Err(RenderError::CantWalk {
|
||||
segment: segment.to_string(),
|
||||
elem: self,
|
||||
})
|
||||
fn walk(&self, segment: &str) -> Result<&dyn ContextElement, WalkError> {
|
||||
Err(WalkError::CantWalk)
|
||||
}
|
||||
}
|
||||
|
||||
impl Walkable for u32 {
|
||||
fn walk(&self, segment: &str) -> Result<&dyn ContextElement, RenderError> {
|
||||
Err(RenderError::CantWalk {
|
||||
segment: segment.to_string(),
|
||||
elem: self,
|
||||
})
|
||||
fn walk(&self, segment: &str) -> Result<&dyn ContextElement, WalkError> {
|
||||
Err(WalkError::CantWalk)
|
||||
}
|
||||
}
|
||||
|
||||
impl Loopable for &str {
|
||||
fn get_loop_elements(&self) -> Result<Vec<&dyn ContextElement>, RenderError> {
|
||||
fn get_loop_elements(&self) -> Vec<&dyn ContextElement> {
|
||||
if self.is_empty() {
|
||||
Ok(Vec::new())
|
||||
Vec::new()
|
||||
} else {
|
||||
Ok(vec![self])
|
||||
vec![self]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Loopable for u32 {
|
||||
fn get_loop_elements(&self) -> Result<Vec<&dyn ContextElement>, RenderError> {
|
||||
Ok(vec![self])
|
||||
fn get_loop_elements(&self) -> Vec<&dyn ContextElement> {
|
||||
vec![self]
|
||||
}
|
||||
}
|
||||
|
||||
impl<I: ContextElement> Loopable for HashMap<&str, I> {
|
||||
fn get_loop_elements(&self) -> Result<Vec<&dyn ContextElement>, RenderError> {
|
||||
Ok(vec![self])
|
||||
fn get_loop_elements(&self) -> Vec<&dyn ContextElement> {
|
||||
vec![self]
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user