Skip to main content

ExpressionEngine

Trait ExpressionEngine 

Source
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 engine
  • cel: 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§

Source

fn engine_prefix(&self) -> &str

Returns the prefix that routes expressions to this engine (e.g., “cel”, “js”).

Source

fn evaluate( &self, expression: &str, input: &Value, vars: &HashMap<String, Value>, ) -> WorkflowResult<Value>

Evaluates an expression against the given input with variable bindings.

Implementors§