camel-language-api 0.2.1

Language trait API for rust-camel (Expression, Predicate)
Documentation

camel-language-api

Language trait API for rust-camel (Expression, Predicate)

Overview

camel-language-api defines the core traits for the rust-camel Languages subsystem, inspired by Apache Camel's Language SPI.

Traits

Trait Description
Language Factory that produces Expression and Predicate instances from scripts
Expression Evaluates a script against an Exchange, returning a serde_json::Value
Predicate Evaluates a script against an Exchange, returning a bool

Error Handling

All operations return Result<_, LanguageError> with variants:

  • ParseError — invalid expression syntax
  • EvalError — runtime evaluation failure
  • UnknownVariable — referenced variable not found
  • NotFound — language not registered

Usage

use camel_language_api::{Language, Expression, Predicate, LanguageError};
use camel_api::exchange::Exchange;

fn evaluate_with(lang: &dyn Language, exchange: &Exchange) -> Result<(), LanguageError> {
    let expr = lang.create_expression("${header.name}")?;
    let value = expr.evaluate(exchange)?;

    let pred = lang.create_predicate("${header.type} == 'order'")?;
    let matches = pred.matches(exchange)?;

    Ok(())
}

License

Apache-2.0