pub struct Expression { /* private fields */ }Expand description
A parsed boolean expression over a JSON context.
See the module documentation for the grammar and the evaluation semantics. Serializes as its source string; deserializing parses the string and rejects invalid expressions. Two expressions are equal when their sources are equal.
§Examples
use ironflow_engine::expression::Expression;
use serde_json::json;
let expr: Expression = "steps[\"risk-assessment\"].output.level == \"high\"".parse()?;
let ctx = json!({"steps": {"risk-assessment": {"output": {"level": "high"}}}});
assert!(expr.evaluate(&ctx));Implementations§
Source§impl Expression
impl Expression
Sourcepub fn parse(src: &str) -> Result<Self, ExpressionError>
pub fn parse(src: &str) -> Result<Self, ExpressionError>
Parse an expression.
§Errors
Returns an ExpressionError when the source is empty, too long, too
deeply nested, lexically or syntactically invalid, or uses a path root
outside EXPRESSION_ROOTS.
§Examples
use ironflow_engine::expression::Expression;
let expr = Expression::parse("output.amount > 10000")?;
assert_eq!(expr.source(), "output.amount > 10000");
assert!(Expression::parse("output.amount >").is_err());Sourcepub fn evaluate(&self, ctx: &Value) -> bool
pub fn evaluate(&self, ctx: &Value) -> bool
Evaluate the expression against a JSON context.
Never fails: missing paths resolve to null and type mismatches
evaluate to false.
§Examples
use ironflow_engine::expression::Expression;
use serde_json::json;
let expr = Expression::parse("labels.priority > 3")?;
assert!(expr.evaluate(&json!({"labels": {"priority": "5"}})));
assert!(!expr.evaluate(&json!({"labels": {}})));Trait Implementations§
Source§impl Clone for Expression
impl Clone for Expression
Source§impl Debug for Expression
impl Debug for Expression
Source§impl<'de> Deserialize<'de> for Expression
impl<'de> Deserialize<'de> for Expression
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Display for Expression
impl Display for Expression
impl Eq for Expression
Source§impl From<Expression> for String
impl From<Expression> for String
Source§fn from(expr: Expression) -> Self
fn from(expr: Expression) -> Self
Converts to this type from the input type.
Source§impl FromStr for Expression
impl FromStr for Expression
Source§impl PartialEq for Expression
impl PartialEq for Expression
Source§impl Serialize for Expression
impl Serialize for Expression
Auto Trait Implementations§
impl Freeze for Expression
impl RefUnwindSafe for Expression
impl Send for Expression
impl Sync for Expression
impl Unpin for Expression
impl UnsafeUnpin for Expression
impl UnwindSafe for Expression
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.