Add a new trait to ContextElement for Truthiness.

Before I was relying on Loopable to both determine truthiness and get a list of elements to loop over. This will no longer work since I need to only set $idx and $len when iterating over actual arrays, as opposed to all truthy values, so I've finally made truthiness explicit.
This commit is contained in:
Tom Alexander
2020-05-24 16:16:43 -04:00
parent 055d88984e
commit 59ee4f508f
6 changed files with 74 additions and 1 deletions

View File

@@ -5,10 +5,20 @@ use std::any::Any;
use std::{cmp::Ordering, fmt::Debug};
pub trait ContextElement:
Debug + Walkable + Renderable + Loopable + CloneIntoBoxedContextElement + CompareContextElement
Debug
+ Truthiness
+ Walkable
+ Renderable
+ Loopable
+ CloneIntoBoxedContextElement
+ CompareContextElement
{
}
pub trait Truthiness {
fn is_truthy(&self) -> bool;
}
pub trait Walkable {
fn walk(&self, segment: &str) -> Result<&dyn ContextElement, WalkError>;
}