ferricel-core 0.1.2

Core compiler and runtime library for ferricel (CEL → Wasm)
Documentation
ferricel-core-0.1.2 has been yanked.

ferricel-core

Docs

ferricel-core is the Rust library that powers ferricel. It provides a compiler and runtime for CEL (Common Expression Language), targeting WebAssembly as the compilation output.

Use it to embed CEL compilation and evaluation directly in your Rust program.

Usage

Basic evaluation

use ferricel_core::{compiler, runtime};

let wasm = compiler::Builder::new()
    .build()
    .compile("x * 2 + 1")?;

let result = runtime::Builder::new()
    .with_wasm(wasm)
    .build()?
    .eval(Some(r#"{"x": 10}"#))?;

assert_eq!(result, "21");

Host extensions

Register host-provided functions that a CEL expression can call at runtime:

use ferricel_core::{compiler, runtime};
use ferricel_types::extensions::ExtensionDecl;

let abs_decl = ExtensionDecl {
    namespace: None,
    function: "abs".to_string(),
    receiver_style: false,
    global_style: true,
    num_args: 1,
};

let wasm = compiler::Builder::new()
    .with_extension(abs_decl.clone())
    .build()
    .compile("abs(x)")?;

let result = runtime::Builder::new()
    .with_extension(abs_decl, |args| {
        let n = args[0].as_i64().unwrap_or(0);
        Ok(serde_json::Value::Number(n.abs().into()))
    })
    .with_wasm(wasm)
    .build()?
    .eval(Some(r#"{"x": -42}"#))?;

assert_eq!(result, "42");

For more examples (logging, custom Wasmtime config, protobuf bindings, performance tips), see the user guide.

Related crates