diff options
| author | Onur Gündüz <ogunduz@gmail.com> | 2026-09-29 17:32:03 +0200 |
|---|---|---|
| committer | Onur Gündüz <ogunduz@gmail.com> | 2026-09-29 17:32:03 +0200 |
| commit | a489aaf4332df58886205cebeffb983819dfef96 (patch) | |
| tree | 5d35976f7fabde55bd54d3a2b3d04924f62e1c30 | |
| parent | 8b3aa7600b92c170e56c26c7b68f28158df76549 (diff) | |
| download | ele-a489aaf4332df58886205cebeffb983819dfef96.tar.gz ele-a489aaf4332df58886205cebeffb983819dfef96.zip | |
Restore Filterable usage and stable Rust installation
| -rw-r--r-- | README.md | 32 |
1 files changed, 30 insertions, 2 deletions
@@ -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<Value<'_>> { + 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). |
