condition_matcher/
result.rs

1use crate::{condition::{ConditionMode, ConditionOperator}, error::MatchError};
2
3/// Result of a match operation with detailed information
4#[derive(Debug, Clone)]
5pub struct MatchResult {
6    /// Whether the overall match succeeded
7    pub matched: bool,
8    /// Individual results for each condition
9    pub condition_results: Vec<ConditionResult>,
10    /// The matching mode used
11    pub mode: ConditionMode,
12}
13
14impl MatchResult {
15    /// Returns true if the match succeeded
16    pub fn is_match(&self) -> bool {
17        self.matched
18    }
19
20    /// Returns the conditions that passed
21    pub fn passed_conditions(&self) -> Vec<&ConditionResult> {
22        self.condition_results.iter().filter(|r| r.passed).collect()
23    }
24
25    /// Returns the conditions that failed
26    pub fn failed_conditions(&self) -> Vec<&ConditionResult> {
27        self.condition_results
28            .iter()
29            .filter(|r| !r.passed)
30            .collect()
31    }
32}
33
34/// Result of evaluating a single condition
35#[derive(Debug, Clone)]
36pub struct ConditionResult {
37    /// Whether this condition passed
38    pub passed: bool,
39    /// Description of what was checked
40    pub description: String,
41    /// The actual value that was compared (as string for display)
42    pub actual_value: Option<String>,
43    /// The expected value (as string for display)
44    pub expected_value: Option<String>,
45    /// Error if evaluation failed
46    pub error: Option<MatchError>,
47}
48/// Result of evaluating a JSON condition
49#[cfg(feature = "json_condition")]
50#[derive(Debug, Clone)]
51pub struct JsonConditionResult {
52    /// Whether this condition passed
53    pub passed: bool,
54    /// The field that was checked
55    pub field: String,
56    /// The operator used
57    pub operator: ConditionOperator,
58    /// The expected value
59    pub expected: serde_json::Value,
60    /// The actual value (if found)
61    pub actual: Option<serde_json::Value>,
62    /// Error message if evaluation failed
63    pub error: Option<String>,
64}
65
66/// Result of evaluating a JSON nested condition group
67#[cfg(feature = "json_condition")]
68#[derive(Debug, Clone)]
69pub struct JsonEvalResult {
70    /// Whether the overall group matched
71    pub matched: bool,
72    /// Results of individual conditions
73    pub details: Vec<JsonConditionResult>,
74}