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
Cowtypes - Extensible: Add custom operators via the
Operatortrait - 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:
- Compilation: JSON logic is parsed into
CompiledLogicwith OpCode dispatch - Evaluation: Compiled logic is evaluated against data using direct dispatch
This design enables sharing compiled logic across threads and eliminates repeated parsing overhead.
Structs§
- Compiled
Logic - Compiled logic that can be evaluated multiple times across different data.
- Context
Frame - A single frame in the context stack (for temporary/nested contexts)
- Context
Stack - Context stack for nested evaluations
- Data
Logic - The main DataLogic engine for compiling and evaluating JSONLogic expressions.
- Evaluation
Config - Main configuration structure for DataLogic evaluation behavior
- Execution
Step - Captures state at each evaluation step.
- Expression
Node - Represents a node in the expression tree for flow diagram rendering.
- Numeric
Coercion Config - Configuration for numeric coercion behavior
- Trace
Collector - Collector for execution steps during traced evaluation.
- Traced
Result - The result of a traced evaluation, containing both the result and execution trace.
Enums§
- Compiled
Node - A compiled node representing a single operation or value in the logic tree.
- Division
ByZero Handling - Defines how to handle division by zero
- Error
- Error type for DataLogic operations
- NanHandling
- Defines how to handle NaN (Not a Number) scenarios in arithmetic operations
- OpCode
- OpCode enum for fast built-in operator lookup
- Truthy
Evaluator - Defines how to evaluate truthiness of values
Traits§
- Evaluator
- Trait for recursive evaluation of logic expressions.
- Operator
- Trait for implementing custom operators.
Type Aliases§
- Result
- Result type for DataLogic operations