quantor
Declarative logic for iterators and collections.
quantor lets you express conditions like forall, exists, none, and existsforall directly over data — making filtering, validation, and testing expressive, readable, and idiomatic.
Why quantor?
Rust's iterator methods are powerful, but when you want to write logic that reads like:
- "All elements are even"
- "At least one user is active"
- "Exactly three items matched a condition"
you're often stuck with .all(), .any(), .filter().count(), and some assert! noise.
With quantor, your code becomes declarative and reflects the logic you care about, not the mechanics.
Highlights
- Quantifiers —
forall,exists,none,exactly_one,exactly_n,all_equal,pairwise,forallexists, and more. - Assertions — Runtime logic assertions like
assert_forall!,assert_unique!,assert_pairwise!, with expressive failure output. - Predicate-based selection — Filter, deduplicate, or extract based on logic:
select_where,select_unique,select_duplicates. - Diagnostics — Inspect failing indices, collect mismatches, or integrate with fuzzing tools using
QuantorError. - Rust-native, ergonomic API – Works with any
IntoIterator, zero dependencies, and optional.method()trait extension.
Example & Comparison
If you're validating product data from an online shop:
use ;
let products = vec!;
let policies = vec!;
// All quantify!-macro options reside as functions in the quantor crate.
// Each policy must be satisfied by at least one product.
quantify!?;
// At least one product is eco-friendly.
quantify!?;
// All products are priced.
forall?;
// IDs are unique.
assert_unique!;
This is readable, declarative, and robust – and every check returns a Result with index-level error diagnostics, while the quantify! macro makes sure you can write conditions comfortably.
Installation
Add quantor to your Cargo.toml:
quantor = "0.1"
Optional features:
method-api— Enables.forall(),.exists(),.select_where(), etc. on slices and iterators.debug-tools— Enablesdebug_assert_*anddebug_*macros for non-panicking diagnostics.
📚 Documentation
See docs.rs for full API documentation and examples.
FAQ
Why does forall return Result<(), QuantorError> instead of bool?
Because failed logical checks are diagnostics, not just false. You get indexed errors and rich messages, not just silent failures.
What’s the difference between select_where and .filter()?
select_where is a semantic wrapper — it describes intent. It’s also easier to reuse and test.
Contributing & Feedback
If quantor made your validation or test code cleaner, I'd love to hear about it.
Have ideas? Open an issue or PR!