pub trait ExpressionEngine: Send + Sync {
// Required methods
fn engine_prefix(&self) -> &str;
fn evaluate(
&self,
expression: &str,
input: &Value,
vars: &HashMap<String, Value>,
) -> WorkflowResult<Value>;
}Expand description
Trait for pluggable expression evaluation engines.
Implement this trait to add support for expression languages beyond JQ
(e.g., CEL, JavaScript). Register engines with WorkflowRunner::with_expression_engine().
Expression routing uses the engine: prefix convention:
jq: .foo→ JQ enginecel: payload.model.startsWith("gpt")→ CEL engine- No prefix → default engine (JQ)
§Example
use async_trait::async_trait;
use serde_json::Value;
use std::collections::HashMap;
use swf_runtime::{ExpressionEngine, WorkflowResult};
struct CelEngine;
#[async_trait]
impl ExpressionEngine for CelEngine {
fn engine_prefix(&self) -> &str { "cel" }
fn evaluate(
&self,
expression: &str,
input: &Value,
vars: &HashMap<String, Value>,
) -> WorkflowResult<Value> {
// Implement CEL evaluation here
Ok(Value::Null)
}
}Required Methods§
Sourcefn engine_prefix(&self) -> &str
fn engine_prefix(&self) -> &str
Returns the prefix that routes expressions to this engine (e.g., “cel”, “js”).