Skip to main content

RecursiveComparison

Struct RecursiveComparison 

Source
pub struct RecursiveComparison<'a, S, R> { /* private fields */ }
Available on crate feature recursive only.
Expand description

Data of an actual assertion in field-by-field recursive comparison mode.

It wraps a Spec and holds additional options for the field-by-field recursive comparison, such as which fields to compare and which to ignore.

See the module documentation for details about field-by-field recursive comparison.

Implementations§

Source§

impl<'a, S, R> RecursiveComparison<'a, S, R>

Source

pub fn comparing_only_field(self, field_path: impl Into<Path<'a>>) -> Self

Adds one field that shall be compared in a field-by-field recursive comparison.

This method can be called multiple times to add several paths to the list of paths to be compared. Each call of this method adds the given field-path to the list of compared paths.

Fields are addressed by their path. To learn how to specify a path and its syntax, see the documentation of the Path struct.

If the same path is added to the list of ignored paths, this path is effectively ignored. Ignored paths take precedence over compared ones.

Source

pub fn comparing_only_fields<P>( self, list_of_field_path: impl IntoIterator<Item = P>, ) -> Self
where P: Into<Path<'a>>,

Adds multiple fields to the list of fields to be compared in a field-by-field recursive comparison.

This method can be called multiple times. Each call of this method extends the list of compared fields with the given paths.

Fields are addressed by their path. To learn how to specify a path and its syntax, see the documentation of the Path struct.

If the same path is added to the list of ignored paths, this path is effectively ignored. Ignored paths take precedence over compared ones.

Source

pub fn ignoring_field(self, field_path: impl Into<Path<'a>>) -> Self

Adds one field that shall be ignored in a field-by-field recursive comparison.

This method can be called multiple times to add several paths to the list of paths to be ignored. Each call of this method adds the given field-path to the list of ignored paths.

Fields are addressed by their path. To learn how to specify a path and its syntax, see the documentation of the Path struct.

If the same path is added to the list of compared paths, this path is effectively ignored. Ignored paths take precedence over compared paths.

Source

pub fn ignoring_fields<P>( self, list_of_field_path: impl IntoIterator<Item = P>, ) -> Self
where P: Into<Path<'a>>,

Adds multiple fields to the list of fields to be ignored in a field-by-field recursive comparison.

This method can be called multiple times. Each call of this method extends the list of ignored fields with the given paths.

Fields are addressed by their path. To learn how to specify a path and its syntax, see the documentation of the Path struct.

If the same path is added to the list of compared paths, this path is effectively ignored. Ignored paths take precedence over compared paths.

Source

pub fn ignoring_not_expected_fields(self) -> Self

Specifies that the recursive comparison shall ignore fields that are not present in the expected value.

By default, the recursive comparison tries to compare all fields of the actual value (subject). If a field of the actual value is not present in the expected value, the assertion fails.

With this option, we can tell the recursive comparison to ignore fields that are not present in the expected value. This is useful when not all fields are relevant to be compared for a specific test case.

Trait Implementations§

Source§

impl<S, E, R> AssertEquality<E> for RecursiveComparison<'_, S, R>

Source§

fn is_equal_to(self, expected: E) -> Self

Verifies that the subject is equal to some other value. Read more
Source§

fn is_not_equal_to(self, expected: E) -> Self

Verifies that the subject is not equal to some other value. Read more
Source§

impl<S, R> AssertEquivalence<Value> for RecursiveComparison<'_, S, R>

Source§

fn is_equivalent_to(self, expected: Value) -> Self

Verifies that the subject is equivalent to the expected value of type Value. Read more
Source§

fn is_not_equivalent_to(self, expected: Value) -> Self

Verifies that the subject is not equivalent to the expected value of type Value. Read more
Source§

impl<S, R> DoFail for RecursiveComparison<'_, S, R>
where R: FailingStrategy,

Source§

fn do_fail_with(&mut self, failures: impl IntoIterator<Item = AssertFailure>)

Fails the assertion with the given AssertFailures according to the current failing strategy of the Spec or other implementing spec-like struct.
Source§

fn do_fail_with_message(&mut self, message: impl Into<String>)

Fails the assertion with the given failure message according to the current failing strategy of the Spec or other implementing spec-like struct.
Source§

impl<S, R> GetFailures for RecursiveComparison<'_, S, R>

Source§

fn has_failures(&self) -> bool

Returns whether there are assertion failures collected so far.
Source§

fn failures(&self) -> Vec<AssertFailure>

Returns the assertion failures that have been collected so far.
Source§

fn display_failures(&self) -> Vec<String>

Returns the assertion failures collected so far as formatted text.
Source§

impl<S> SoftPanic for RecursiveComparison<'_, S, CollectFailures>

Source§

fn soft_panic(&self)

Turns assertions into “soft assertions”. Read more

Auto Trait Implementations§

§

impl<'a, S, R> Freeze for RecursiveComparison<'a, S, R>
where S: Freeze, R: Freeze,

§

impl<'a, S, R> RefUnwindSafe for RecursiveComparison<'a, S, R>

§

impl<'a, S, R> Send for RecursiveComparison<'a, S, R>
where S: Send, R: Send,

§

impl<'a, S, R> Sync for RecursiveComparison<'a, S, R>
where S: Sync, R: Sync,

§

impl<'a, S, R> Unpin for RecursiveComparison<'a, S, R>
where S: Unpin, R: Unpin,

§

impl<'a, S, R> UnsafeUnpin for RecursiveComparison<'a, S, R>
where S: UnsafeUnpin, R: UnsafeUnpin,

§

impl<'a, S, R> UnwindSafe for RecursiveComparison<'a, S, R>
where S: UnwindSafe, R: UnwindSafe,

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.