Crate condition_matcher

Crate condition_matcher 

Source
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 and regex support

§Quick Start

use condition_matcher::{Matcher, MatcherMode, Condition, ConditionSelector, ConditionOperator, Matchable, MatchableDerive};

#[derive(MatchableDerive, PartialEq, Debug)]
struct User {
    name: String,
    age: u32,
}

let user = User { name: "Alice".to_string(), age: 30 };

let mut matcher = Matcher::new(MatcherMode::AND);
matcher.add_condition(Condition {
    selector: ConditionSelector::FieldValue("age", &18u32),
    operator: ConditionOperator::GreaterThanOrEqual,
});

assert!(matcher.run(&user).unwrap());

§Builder API

use condition_matcher::{MatcherBuilder, MatcherMode};

let matcher = MatcherBuilder::<&str>::new()
    .mode(MatcherMode::AND)
    .length_gte(4)
    .value_not_equals("bad")
    .build();

assert!(matcher.run(&"good").unwrap());

Re-exports§

pub use condition::Condition;
pub use condition::ConditionOperator;
pub use condition::ConditionSelector;
pub use matcher::field;
pub use matcher::ConditionResult;
pub use matcher::FieldConditionBuilder;
pub use matcher::MatchError;
pub use matcher::MatchResult;
pub use matcher::Matchable;
pub use matcher::Matcher;
pub use matcher::MatcherBuilder;
pub use matcher::MatcherMode;

Modules§

condition
matcher
Matcher Module

Derive Macros§

MatchableDerive
Derive macro for implementing the Matchable trait.