Crate datalogic_rs

Crate datalogic_rs 

Source
Expand description

§datalogic-rs

A high-performance, thread-safe Rust implementation of JSONLogic.

§Overview

datalogic-rs provides a powerful rule evaluation engine that compiles JSONLogic expressions into optimized, reusable structures that can be evaluated across multiple threads with zero overhead.

§Key Features

  • Compilation-based optimization: Parse once, evaluate many times
  • Thread-safe by design: Share compiled logic across threads with Arc
  • 50+ built-in operators: Complete JSONLogic compatibility plus extensions
  • Zero-copy operations: Minimize allocations with Cow types
  • Extensible: Add custom operators via the Operator trait
  • Structured templates: Preserve object structure for dynamic outputs

§Quick Start

use datalogic_rs::DataLogic;
use serde_json::json;

let engine = DataLogic::new();

// Compile your logic once
let logic = json!({"==": [{"var": "status"}, "active"]});
let compiled = engine.compile(&logic).unwrap();

// Evaluate with different data
let data = json!({"status": "active"});
let result = engine.evaluate_owned(&compiled, data).unwrap();
assert_eq!(result, json!(true));

§Architecture

The library uses a two-phase approach:

  1. Compilation: JSON logic is parsed into CompiledLogic with OpCode dispatch
  2. Evaluation: Compiled logic is evaluated against data using direct dispatch

This design enables sharing compiled logic across threads and eliminates repeated parsing overhead.

Structs§

CompiledLogic
Compiled logic that can be evaluated multiple times across different data.
ContextFrame
A single frame in the context stack (for temporary/nested contexts)
ContextStack
Context stack for nested evaluations
DataLogic
The main DataLogic engine for compiling and evaluating JSONLogic expressions.

Enums§

CompiledNode
A compiled node representing a single operation or value in the logic tree.
Error
Error type for DataLogic operations
OpCode
OpCode enum for fast built-in operator lookup

Traits§

Evaluator
Trait for recursive evaluation of logic expressions.
Operator
Trait for implementing custom operators.

Type Aliases§

Result
Result type for DataLogic operations