RuleMatcher

Struct RuleMatcher 

Source
pub struct RuleMatcher<'a, T: Matchable> {
    pub mode: ConditionMode,
    pub conditions: Vec<Condition<'a, T>>,
}
Expand description

A rule-based matcher built from programmatic conditions.

Use MatcherBuilder for a fluent construction API.

§Example

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

let mut matcher: RuleMatcher<i32> = RuleMatcher::new(MatcherMode::AND);
matcher.add_condition(Condition {
    selector: ConditionSelector::Value(42),
    operator: ConditionOperator::Equals,
});

assert!(matcher.matches(&42));

Fields§

§mode: ConditionMode

The logical combination mode (AND, OR, XOR).

§conditions: Vec<Condition<'a, T>>

The conditions to evaluate.

Implementations§

Source§

impl<'a, T: Matchable + 'static> RuleMatcher<'a, T>

Source

pub fn new(mode: ConditionMode) -> Self

Create a new matcher with the specified mode.

Source

pub fn and() -> Self

Create a new matcher with AND mode.

Source

pub fn or() -> Self

Create a new matcher with OR mode.

Source

pub fn xor() -> Self

Create a new matcher with XOR mode.

Source

pub fn add_condition(&mut self, condition: Condition<'a, T>) -> &mut Self

Add a condition to this matcher.

Source

pub fn add_conditions( &mut self, conditions: impl IntoIterator<Item = Condition<'a, T>>, ) -> &mut Self

Add multiple conditions at once.

Trait Implementations§

Source§

impl<'a, T: Debug + Matchable> Debug for RuleMatcher<'a, T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a, T: Matchable + 'static> Evaluate<T> for RuleMatcher<'a, T>

Source§

type Output = MatchResult

The result type for detailed evaluation.
Source§

fn evaluate(&self, value: &T) -> MatchResult

Evaluate with full details (field values, errors, descriptions).
Source§

impl<'a, T: Matchable + 'static> Matcher<T> for RuleMatcher<'a, T>

Source§

fn matches(&self, value: &T) -> bool

Check if this matcher matches the given value.
Source§

fn mode(&self) -> ConditionMode

Get the logical combination mode (AND, OR, XOR).

Auto Trait Implementations§

§

impl<'a, T> Freeze for RuleMatcher<'a, T>

§

impl<'a, T> !RefUnwindSafe for RuleMatcher<'a, T>

§

impl<'a, T> !Send for RuleMatcher<'a, T>

§

impl<'a, T> !Sync for RuleMatcher<'a, T>

§

impl<'a, T> Unpin for RuleMatcher<'a, T>
where T: Unpin,

§

impl<'a, T> !UnwindSafe for RuleMatcher<'a, T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, M> MatcherExt<T> for M
where T: Matchable, M: Matcher<T>,

Source§

fn filter<'a>(&self, values: &'a [T]) -> Vec<&'a T>

Filter values, returning references to those that match.
Source§

fn matches_all(&self, values: &[T]) -> Vec<bool>

Check all values, returning match results as a vector of booleans.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.