MatcherBuilder

Struct MatcherBuilder 

Source
pub struct MatcherBuilder<'a, T: Matchable> { /* private fields */ }
Expand description

A builder for creating matchers with a fluent API

§Example

use condition_matcher::{MatcherBuilder, MatcherMode, ConditionOperator, Matcher};

let matcher = MatcherBuilder::<i32>::new()
    .mode(MatcherMode::AND)
    .value_equals(42)
    .build();

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

Implementations§

Source§

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

Source

pub fn new() -> Self

Create a new builder with default AND mode

Source

pub fn mode(self, mode: ConditionMode) -> Self

Set the matching mode

Source

pub fn value_equals(self, expected: T) -> Self

Add a condition that the value equals the expected value

Source

pub fn value_not_equals(self, expected: T) -> Self

Add a condition that the value does not equal the expected value

Source

pub fn length(self, len: usize, operator: ConditionOperator) -> Self

Add a length condition

Source

pub fn length_equals(self, len: usize) -> Self

Add a condition that length equals the expected value

Source

pub fn length_gte(self, len: usize) -> Self

Add a condition that length is greater than or equal to the expected value

Source

pub fn length_lte(self, len: usize) -> Self

Add a condition that length is less than or equal to the expected value

Source

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

Add a raw condition

Source

pub fn build(self) -> RuleMatcher<'a, T>

Build the matcher

Trait Implementations§

Source§

impl<'a, T: Matchable + 'static> Default for MatcherBuilder<'a, T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<'a, T> !UnwindSafe for MatcherBuilder<'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, 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.