condition_matcher/
condition.rs

1use std::any::Any;
2
3/// Operators for comparing values in conditions
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6pub enum ConditionOperator {
7    /// Exact equality check
8    Equals,
9    /// Inequality check
10    NotEquals,
11    /// Greater than comparison (numeric types)
12    GreaterThan,
13    /// Less than comparison (numeric types)
14    LessThan,
15    /// Greater than or equal comparison (numeric types)
16    GreaterThanOrEqual,
17    /// Less than or equal comparison (numeric types)
18    LessThanOrEqual,
19    /// String contains substring
20    Contains,
21    /// String does not contain substring
22    NotContains,
23    /// String starts with prefix
24    StartsWith,
25    /// String ends with suffix
26    EndsWith,
27    /// Value matches regex pattern
28    Regex,
29    /// Check if value is None/null
30    IsNone,
31    /// Check if value is Some/present
32    IsSome,
33    /// Check if collection is empty
34    IsEmpty,
35    /// Check if collection is not empty
36    IsNotEmpty,
37}
38
39/// Selectors for targeting what to check in a condition
40#[derive(Debug)]
41pub enum ConditionSelector<'a, T> {
42    /// Check the length of a string or collection
43    Length(usize),
44    /// Check the type name
45    Type(String),
46    /// Compare against a specific value
47    Value(T),
48    /// Check a field value by name
49    FieldValue(&'a str, &'a dyn Any),
50    /// Check a nested field path (e.g., ["address", "city"])
51    FieldPath(&'a [&'a str], &'a dyn Any),
52    /// Negate a condition (inverts the result)
53    Not(Box<Condition<'a, T>>),
54}
55
56/// A single condition to evaluate
57#[derive(Debug)]
58pub struct Condition<'a, T> {
59    pub operator: ConditionOperator,
60    pub selector: ConditionSelector<'a, T>,
61}