| Crates.io | rusty-rules |
| lib.rs | rusty-rules |
| version | 0.2.1 |
| created_at | 2025-05-19 22:28:00.982755+00 |
| updated_at | 2025-09-10 12:58:13.886292+00 |
| description | A blazingly fast, flexible, and extensible rules engine written in Rust. |
| homepage | |
| repository | https://github.com/khvzak/rusty-rules |
| max_upload_size | |
| id | 1680498 |
| size | 227,658 |
A blazingly fast, flexible, and extensible rules engine written in Rust. Evaluate complex logical rules against custom data structures using a simple JSON-based DSL. Supports both synchronous and asynchronous fetchers, custom operators, and a variety of matchers.
all, any, and not logical blocks for complex rule hierarchiesvalidation feature)Send/Sync trait bounds with the send feature flagAdd to Cargo.toml:
[dependencies]
rusty-rules = "0.2"
use std::collections::HashMap;
use std::net::IpAddr;
struct MyContext {
method: String,
path: String,
headers: HashMap<String, String>,
addr: IpAddr,
}
use rusty_rules::{Engine, Value};
let mut engine = Engine::new();
engine.register_fetcher("method", |ctx: &MyContext, _args| {
Ok(Value::from(&ctx.method))
});
engine.register_fetcher("header", |ctx: &MyContext, args| {
Ok(args.first().and_then(|name| ctx.headers.get(name)).into())
});
engine.register_fetcher("addr", |ctx: &MyContext, _args| {
Ok(ctx.addr.into())
});
// ...register other fetchers...
use serde_json::json;
let rule = engine.compile_rule(&json!({
"method": "GET",
"header(host)": "www.example.com",
"addr": {
"ip": ["10.0.0.0/8"]
}
})).unwrap();
let ctx = /* MyContext instance */;
assert!(rule.evaluate(&ctx).unwrap());