Crates.io | coolrule |
lib.rs | coolrule |
version | 0.1.0 |
source | src |
created_at | 2023-08-18 15:54:04.737785 |
updated_at | 2023-08-18 15:54:04.737785 |
description | A boolean expression evaluator. A Rust port of boolrule. |
homepage | https://github.com/healeycodes/coolrule |
repository | https://github.com/healeycodes/coolrule |
max_upload_size | |
id | 947940 |
size | 40,100 |
Boolean expression evaluation engine (a port of boolrule to 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).
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!
cargo test