Rust-Runes: A Rule Engine in Rust
A rule engine for embedding business logic in Rust applications, compatible with
Grule's rule language (GRL) and
execution model. Grule's own .grl files load unchanged.
This is an independent implementation; it is not affiliated with the Grule project.
Read the guide for the rule language, built-in functions, execution model, and migrating from Grule.
Installation
[]
= "0.1.0"
Requires Rust 1.83 or later.
Quick Start
Rules say what to do when a condition holds, and usually live in .grl files:
rule LongRide "Long rides get a flat rate" salience 10 {
when
Ride.Distance > 5000 && !Ride.Priced
then
Ride.NetAmount = 143.32;
Ride.Priced = true;
Log("Priced ride of " + Ride.Distance + "m");
}
Facts can be any serializable type. The engine runs rules until none applies, changing the facts in place:
use ;
use ;
use HashMap;
More complete programs are in examples/; run one with
cargo run --example quickstart.
Features
- Grule's rule language: the same grammar, operators and type rules, and all of Grule's built-in functions and methods.
- Grule's execution model: salience,
Retract,Complete, maximum cycles, failed conditions counting as false, listeners andFetchMatchingRules. - Facts from your types through serde, including
DateTimefields and Go-style typed assignment. - Your own functions and methods, including methods on your own types, the counterpart of methods on Go fact structs.
- Cancellation and timeouts for executions.
- Fast: identical conditions across rules are evaluated once, and results are reused until a fact they read changes.
| Benchmark (Apple M5) | 100 rules | 1000 rules | Grule (published) |
|---|---|---|---|
| Execute a fact (Grule's benchmark) | 0.81 µs | 0.82 µs | 9.7 µs / 569 µs |
| Load rules | 2.8 ms | 28.7 ms | 21–99 ms / 210–934 ms |
See Performance for the methodology and more results, and Migrating from Grule for the differences from Grule.
Contributing
Contributions are welcome; see CONTRIBUTING.md. Please report security issues privately, as described in SECURITY.md.
License
MIT