Expand description
§Condition Matcher
A flexible and type-safe condition matching library for Rust with automatic struct field access.
§Features
- Automatic struct matching with derive macro
- Multiple matching modes (AND, OR, XOR)
- Support for various condition types (value, length, type, field)
- String operations (contains, starts_with, ends_with)
- Numeric comparisons on fields
- Detailed match results with error information
- Builder pattern for ergonomic API
- Optional serde, regex, and parallel processing support
§Quick Start
use condition_matcher::{RuleMatcher, MatcherMode, Condition, ConditionSelector, ConditionOperator, MatchableDerive, Matcher, Matchable, MatcherBuilder};
#[derive(MatchableDerive, PartialEq, Debug)]
struct User {
name: String,
age: u32,
}
let user = User { name: "Alice".to_string(), age: 30 };
let mut matcher = MatcherBuilder::<User>::new()
.mode(MatcherMode::AND)
.value_equals(User { name: "Alice".to_string(), age: 30 })
.build();
matcher.add_condition(Condition {
selector: ConditionSelector::FieldValue("age", &18u32),
operator: ConditionOperator::GreaterThanOrEqual,
});
assert!(matcher.matches(&user));§Builder API
use condition_matcher::{MatcherBuilder, MatcherMode, Matcher};
let matcher = MatcherBuilder::<&str>::new()
.mode(MatcherMode::AND)
.length_gte(4)
.value_not_equals("bad")
.build();
assert!(matcher.matches(&"good"));§Batch Operations
ⓘ
use condition_matcher::{batch, JsonMatcher, Matcher};
let matchers: Vec<JsonMatcher> = load_from_database()?;
let records: Vec<Record> = get_records();
// Find which matchers apply to a single record
let applicable = batch::matching(&records[0], &matchers);
// Evaluate all combinations (with parallel feature)
let all_matches = batch::parallel::evaluate_matrix(&records, &matchers);Re-exports§
pub use builder::field;pub use builder::FieldConditionBuilder;pub use builder::MatcherBuilder;
Modules§
- batch
- Batch operations for evaluating matchers against collections.
- builder
- Builder module for creating matchers. Builder pattern for creating matchers.
Structs§
- Condition
- A single condition to evaluate
- Condition
Result - Result of evaluating a single condition
- Match
Result - Result of a match operation with detailed information
- Nested
Condition - A group of conditions combined with a logic mode
- Rule
Matcher - A rule-based matcher built from programmatic conditions.
Enums§
- Condition
Mode - Mode for combining multiple conditions
- Condition
Operator - Operators for comparing values in conditions
- Condition
Selector - Selectors for targeting what to check in a condition
- Match
Error - Errors that can occur during condition matching
Traits§
- Evaluate
- Extended trait for matchers that provide detailed evaluation results.
- Matchable
- Trait for types that can be matched against conditions.
- Matcher
- Core trait for any type that can match against a value.
- Matcher
Ext - Extension trait providing batch operations.
- Predicate
- Trait for individual condition/predicate evaluation.
Type Aliases§
- Matcher
Mode - Alias for
ConditionModefor backwards compatibility.
Derive Macros§
- Matchable
Derive - Derive macro for implementing the
Matchabletrait.