From a489aaf4332df58886205cebeffb983819dfef96 Mon Sep 17 00:00:00 2001 From: Onur Gündüz Date: Tue, 29 Sep 2026 17:32:03 +0200 Subject: Restore Filterable usage and stable Rust installation --- README.md | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d302f1d..505e82f 100644 --- a/README.md +++ b/README.md @@ -4,10 +4,11 @@ Parses and evaluates an [AIP-160](https://google.aip.dev/160)-style filter langu ## Install -Rust 1.88 or newer is required. Clone the repository and install it with Cargo: +Install [Rust](https://rustup.rs/), then run this from a repository checkout: ```bash -cargo install --path . --locked +rustup update stable +cargo +stable install --path . --locked ``` ## CLI usage @@ -59,6 +60,33 @@ let record = json!({"state": "open", "priority": 5}); assert!(filter.evaluate(&record)); ``` +For a custom type, expose its fields through `Filterable`: + +```rust +use aif::{Filterable, Value, parse}; + +struct Issue { + state: String, + priority: i64, +} + +impl Filterable for Issue { + fn field(&self, name: &str) -> Option> { + match name { + "state" => Some(Value::String(&self.state)), + "priority" => Some(Value::Int(self.priority)), + _ => None, + } + } +} + +let expr = parse("state = open AND priority > 3").unwrap().unwrap(); +let filter = expr.compile().unwrap(); +let issue = Issue { state: "open".into(), priority: 5 }; + +assert!(filter.evaluate(&issue)); +``` + ## License Licensed under the [MIT License](LICENSE). -- cgit v1.3.1