1 unstable release
new 0.1.0 | May 4, 2025 |
---|
#53 in #logic
41KB
552 lines
quantor
Declarative quantifiers and logical assertions for Rust iterators and collections.
quantor
provides lightweight, expressive tools for validation, filtering, and testing — with zero dependencies.
✨ Features
quantor
lets you express logic over data in a way that feels natural and readable:
- 📐 Quantifiers — Use familiar constructs like
forall
,exists
,none
, andexactly_one
. - 🧹 Selection utilities — Filter with
select_where
, extract duplicates, check for uniqueness. - 🧠 Structured logic — Run
pairwise
comparisons or validate equality across items. - 🧪 Assertions — Add runtime guarantees with
assert_forall!
,assert_exists!
, etc.
Example
use quantor::{forall, select_where, assert_forall};
let nums = vec![2, 4, 6];
// Check if all elements are even
assert!(forall(&nums, |x| x % 2 == 0));
// Use the macro version for test-friendly assertions
assert_forall!(&nums, |x| x % 2 == 0);
// Extract matching elements
let evens = select_where(&nums, |x| x % 2 == 0);
assert_eq!(evens, vec![&2, &4, &6]);
📦 Installation
Add this to your Cargo.toml
:
quantor = "0.1"
Optional features:
method-api
– Enable.forall()
and other iterator-style methods.debug-tools
– Add debugging macros likedebug_assert_forall!
ordebug_exists!
.
📚 Documentation
See docs.rs for full API documentation and examples.