Ported the get_loop_elements wrapper.
This commit is contained in:
parent
2712126b3c
commit
d758a71fb4
@ -126,7 +126,7 @@ impl Walkable for serde_json::Value {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Loopable for serde_json::Value {
|
impl Loopable for serde_json::Value {
|
||||||
fn get_loop_elements(&self) -> Result<Vec<&dyn ContextElement>, RenderError> {
|
fn get_loop_elements(&self) -> Vec<&dyn ContextElement> {
|
||||||
match self {
|
match self {
|
||||||
serde_json::Value::Null => Ok(Vec::new()),
|
serde_json::Value::Null => Ok(Vec::new()),
|
||||||
serde_json::Value::Bool(boolean) => {
|
serde_json::Value::Bool(boolean) => {
|
||||||
|
@ -23,5 +23,5 @@ pub trait Loopable {
|
|||||||
/// once with the context being the element at that path. Finally,
|
/// once with the context being the element at that path. Finally,
|
||||||
/// if its an array-like value then it will render n-times, once
|
/// if its an array-like value then it will render n-times, once
|
||||||
/// for each element of the array.
|
/// for each element of the array.
|
||||||
fn get_loop_elements(&self) -> Result<Vec<&dyn ContextElement>, RenderError>;
|
fn get_loop_elements(&self) -> Vec<&dyn ContextElement>;
|
||||||
}
|
}
|
||||||
|
@ -197,13 +197,11 @@ impl<'a> DustRenderer<'a> {
|
|||||||
/// block, this will return an empty vector.
|
/// block, this will return an empty vector.
|
||||||
fn get_loop_elements<'b>(
|
fn get_loop_elements<'b>(
|
||||||
&'a self,
|
&'a self,
|
||||||
walk_result: Result<&'b dyn ContextElement, RenderError<'b>>,
|
walk_result: Result<&'b dyn ContextElement, WalkError>,
|
||||||
) -> Result<Vec<&'b dyn ContextElement>, RenderError<'b>> {
|
) -> Vec<&'b dyn ContextElement> {
|
||||||
if let Err(RenderError::NotFound { .. }) = walk_result {
|
match walk_result {
|
||||||
// If reference does not exist in the context, render the else block
|
Err(WalkError::CantWalk) => Vec::new(),
|
||||||
Ok(vec![])
|
Ok(walk_target) => walk_target.get_loop_elements(),
|
||||||
} else {
|
|
||||||
Ok(walk_result?.get_loop_elements()?)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user