https://github.com/healeycodes/coolrule
🧮 Boolean expression evaluation engine. A Rust port of boolrule.
https://github.com/healeycodes/coolrule
boolean-expression evaluator pom
Last synced: 6 months ago
JSON representation
🧮 Boolean expression evaluation engine. A Rust port of boolrule.
- Host: GitHub
- URL: https://github.com/healeycodes/coolrule
- Owner: healeycodes
- Created: 2023-08-16T22:56:30.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-09-17T21:11:02.000Z (over 1 year ago)
- Last Synced: 2025-08-02T21:55:30.784Z (7 months ago)
- Topics: boolean-expression, evaluator, pom
- Language: Rust
- Homepage:
- Size: 19.5 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# coolrule
[](https://github.com/healeycodes/coolrule/actions/workflows/rust.yml) [](https://crates.io/crates/coolrule)
> My blog post: [Porting Boolrule to Rust](https://healeycodes.com/porting-boolrule-to-rust)
Boolean expression evaluation engine (a port of [boolrule](https://github.com/tailsdotcom/boolrule) to Rust).
```rust
// Without context
let expr = coolrule::new("1 in (1, 2, 3) or 2 > 3")?;
let test = expr.test()?; // true
// With context
let expr = coolrule::new("x ∉ (5, 6, 7)")?;
let test = expr.test_with_context(
HashMap::from([(vec!["x"], Value::Number(8.0))])
)?; // true
```
The boolrule test suite has also been ported (and passes) see `lib.rs`.
Expressions are parsed via PEG parser combinators (powered by [pom](https://github.com/J-F-Liu/pom)).
It's around 3x faster than the Python version (before any kind of optimization work).
I'm still learning how to write idiomatic Rust so if you see anything strange please let me know!
## Tests
`cargo test`