Rust Rule Engine v0.10.1 π¦β‘
A high-performance rule engine for Rust with RETE-UL algorithm (2-24x faster), CLIPS-inspired features, Plugin System, and GRL (Grule Rule Language) support. Designed for production use with ~97% Drools compatibility.
π GitHub | Documentation | Crates.io
β¨ What's New in v0.10.1
π RETE Performance Optimization + Comprehensive Benchmarks!
- β‘ RETE Fixed - Eliminated infinite loop issue, now blazing fast
- π Benchmarked - Comprehensive comparison: Traditional vs RETE
- π₯ 2-24x Faster - RETE shows 2x speedup at 10 rules, 24x at 50+ rules
- β Production Ready - Max iterations guard, optimized agenda management
- π Scalability Proven - ~5Β΅s per rule, scales linearly
Previous Updates (v0.10.0)
- π§ Function Calls in WHEN - Call AI/custom functions directly in rule conditions
- π Template System - Type-safe schema definitions for structured facts
- π Defglobal - Global variables with thread-safe access
- π Drools Compatibility - ~97% Drools parity
See Release Notes β | CLIPS Features Guide β
π Key Features
Native Engine
- GRL Support - Full Grule-compatible syntax
- Function Calls in WHEN - Call functions directly in conditions (NEW in v0.10.0)
- Plugin System - 44+ actions, 33+ functions
- Knowledge Base - Centralized rule management
- Type Safety - Rust's compile-time guarantees
- Production Ready - REST API, monitoring, health checks
RETE-UL Engine (Recommended for 50+ rules)
- π 2-24x Faster - Proven benchmarks vs traditional engine (v0.10.1)
- π₯ RETE Algorithm - High-performance pattern matching (~97% Drools parity)
- π Template System - Type-safe structured facts (v0.10.0)
- π Defglobal - Global variables across firings (v0.10.0)
- β‘ Incremental Updates - Only re-evaluate affected rules
- π§ Working Memory - FactHandles with insert/update/retract
- π― Advanced Agenda - Salience, activation groups, no-loop, max iterations guard
- π Variable Binding - Cross-pattern $var syntax
- πΎ Memoization - 99.99% cache hit rate
Choose Your Engine:
- < 10 rules β Native Engine (simpler API, plugin support)
- 10-50 rules β Either (RETE ~2x faster)
- 50+ rules β RETE-UL Engine (2-24x faster, highly recommended)
- Both needs β Hybrid approach
π Performance at 50 rules: Traditional 1.72ms vs RETE 70Β΅s = 24.4x faster!
π Engine Comparison Guide β | Quick Start Guide β
π¦ Installation
[]
= "0.10.1"
Optional Features
# Enable streaming support
= { = "0.10.1", = ["streaming"] }
π― Quick Start
Option 1: Native Engine (Simple & Plugin-rich)
use ;
GRL Rule Example (rules/discount.grl):
rule "GoldCustomerDiscount" salience 10 {
when
customer.tier == "gold" && order.amount > 1000
then
order.discount = order.amount * 0.15;
Log("Applied 15% gold customer discount");
}
Option 2: RETE-UL Engine (High Performance)
use ;
π§ NEW: Function Calls in WHEN Clause
v0.10.0 introduces the ability to call functions directly in rule conditions!
β¨ Before (Rule Chaining)
rule "Step1: Call AI" {
when Customer.needsCheck == true
then set(Customer.sentiment, aiSentiment(Customer.feedback));
}
rule "Step2: Check Result" {
when Customer.sentiment == "negative"
then Alert("Negative feedback detected!");
}
β¨ After (Direct Function Calls)
rule "Check Sentiment" {
when aiSentiment(Customer.feedback) == "negative"
then Alert("Negative feedback detected!");
}
π Use Cases
AI/ML Integration:
rule "Fraud Detection" {
when aiFraud(Transaction.amount, Transaction.userId) == true
then set(Transaction.status, "blocked");
}
Business Logic:
rule "Credit Check" {
when creditScore(Customer.id) > 750
then set(Customer.tier, "premium");
}
Data Validation:
rule "Email Validation" {
when validateEmail(User.email) == false
then set(User.error, "Invalid email format");
}
See ai_functions_in_when.rs for complete examples!
π Documentation
π Getting Started
- Quick Start Guide - Choose and use your engine
- Engine Comparison - Native vs RETE-UL decision guide
- Examples - 30+ working examples
π§ Core Features
- Features Guide - All engine features explained
- Plugin System - Built-in plugins & custom creation
- Advanced Usage - Complex patterns & workflows
- AI Integration - ML models & LLM integration
π RETE-UL Engine
- RETE Guide - Complete RETE-UL documentation
- CLIPS Features - Template System & Defglobal
- CLIPS Analysis - Feature comparison & roadmap
π Distributed & Production
- Streaming Engine - Real-time stream processing
- Distributed Setup - Getting started with distributed mode
- Distributed Architecture - Cluster setup & scaling
- Distributed Features - Complete distributed guide
- Performance Guide - Benchmarks & optimization
π Reference
- API Reference - Complete API documentation
- GRL Syntax - Rule language reference
- Roadmap - Future plans & upcoming features
- Release Notes - What's new in v0.10.0
- Changelog - Complete changelog
π₯οΈ VS Code Extension
Install GRL Syntax Highlighting for .grl files:
Features:
- Syntax highlighting for GRL
- Snippets for rules, actions, functions
- Auto-detection of
.grlfiles
Install: Search grl-syntax-highlighting in VS Code Extensions
π― Use Cases
1. Business Rules Engine
// Pricing, discounts, loyalty programs
rule "VIPDiscount"
2. Fraud Detection
// Real-time fraud scoring
rule "HighRiskTransaction"
3. Workflow Automation
// Multi-step approval workflows
rule "ManagerApproval" agenda-group "approvals"
4. Real-Time Systems
// IoT, monitoring, alerts
rule "TemperatureAlert"
More examples: examples/ directory
β‘ Performance
RETE-UL Engine Benchmarks
- Pattern Matching: ~4Β΅s per fact insertion (1000 facts)
- Incremental Updates: 2x speedup (only affected rules)
- Memoization: 99.99% cache hit rate
- Template Validation: 1-2Β΅s per fact
- Global Variables: 120ns read, 180ns write
Native Engine Benchmarks
- Rule Execution: ~10Β΅s per rule (simple conditions)
- Plugin Actions: ~2-5Β΅s per action call
- Facts Access: O(1) HashMap lookups
Comparison: Performance Guide
πΊοΈ Roadmap
v0.11.0 (Next Release - 2-3 weeks)
- Deffacts - Initial fact definitions (CLIPS feature)
- Test CE - Arbitrary conditions in patterns
- Multi-field Variables - Array pattern matching
- Target: ~98-99% Drools compatibility
v1.0.0 (Stable Release)
- Full API stability guarantee
- 99% Drools compatibility
- Performance optimizations
- Comprehensive benchmarks
- Production hardening
Future Features
- Truth Maintenance System (TMS)
- Module System for rule organization
- Backward Chaining support
- Interactive debugger
- Visual rule builder UI
π Comparison with Other Engines
| Feature | Rust Engine | Drools | CLIPS |
|---|---|---|---|
| Performance | β‘ Excellent | Good | Excellent |
| Type Safety | β Compile-time | β οΈ Runtime | β οΈ Runtime |
| Memory Safety | β Guaranteed | β JVM | β Manual |
| RETE Algorithm | β RETE-UL | β Full RETE | β Full RETE |
| Pattern Matching | β Advanced | β Advanced | β Advanced |
| Plugin System | β Native | β οΈ Limited | β No |
| GRL Support | β Full | N/A | N/A |
| Template System | β v0.10.0 | β | β |
| Defglobal | β v0.10.0 | β | β |
| Drools Compatibility | ~97% | 100% | ~60% |
| Learning Curve | Medium | High | High |
| Ecosystem | Growing | Mature | Mature |
π€ Contributing
We welcome contributions! See CONTRIBUTING.md for guidelines.
Development Setup
# Clone repository
# Run tests
# Run examples
# Build documentation
π License
This project is licensed under the MIT License - see LICENSE file.
π Acknowledgments
Inspired by:
- Drools - JBoss Rule Engine
- CLIPS - NASA C Language Integrated Production System
- Grule - Go Rule Engine
Special Thanks:
- Rust community for amazing tools and libraries
- Contributors who helped improve the engine
- Users providing valuable feedback
π Support
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Email: tonthatvu.hust@gmail.com
π Stats
Made with β€οΈ by Ton That Vu