pub fn container_eq<ActualContainerT, ExpectedContainerT>(
    expected: ExpectedContainerT
) -> ContainerEqMatcher<ActualContainerT, ExpectedContainerT>
where ActualContainerT: PartialEq<ExpectedContainerT> + Debug + ?Sized, ExpectedContainerT: Debug,
Expand description

Matches a container equal (in the sense of ==) to expected.

This is similar to crate::matchers::eq except that an assertion failure message generated from this matcher will include the missing and unexpected items in the actual value, e.g.:

Expected container to equal [1, 2, 3]
  but was: [1, 2, 4]
  Missing: [3]
  Unexpected: [4]

The actual value must be a container such as a Vec, an array, or a dereferenced slice. More precisely, a shared borrow of the actual value must implement IntoIterator whose Item type implements PartialEq<ExpectedT>, where ExpectedT is the element type of the expected value.

If the container type is a Vec, then the expected type may be a slice of the same element type. For example:

let vec = vec![1, 2, 3];
verify_that!(vec, container_eq([1, 2, 3]))?;

As an exception, if the actual type is a Vec<String>, the expected type may be a slice of &str:

let vec: Vec<String> = vec!["A string".into(), "Another string".into()];
verify_that!(vec, container_eq(["A string", "Another string"]))?;

These exceptions allow one to avoid unnecessary allocations in test assertions.

One can also check container equality of a slice with an array. To do so, dereference the slice:

let value = &[1, 2, 3];
verify_that!(*value, container_eq([1, 2, 3]))?;

Otherwise, the actual and expected types must be identical.

Performance note: In the event of a mismatch leading to an assertion failure, the construction of the lists of missing and unexpected values uses a naive algorithm requiring time proportional to the product of the sizes of the expected and actual values. This should therefore only be used when the containers are small enough that this is not a problem.