pub fn superset_of<ElementT: Debug + PartialEq, ActualT: Debug + ?Sized, ExpectedT: Debug>(
    subset: ExpectedT
) -> impl Matcher<ActualT = ActualT>
Expand description

Matches a container containing all of the items in the given container subset.

The element type ElementT must implement PartialEq to allow element comparison.

ActualT and ExpectedT can each be any container a reference to which implements IntoIterator. For instance, ActualT and ExpectedT can be a common container like Vec or arrays. They need not be the same container type.

let value = vec![1, 2, 3];
verify_that!(value, superset_of([1, 2]))?;  // Passes
let array_value = [1, 2, 3];
verify_that!(array_value, superset_of([1, 2]))?;  // Passes
verify_that!(value, superset_of([1, 2, 4]))?;  // Fails: 4 is not in the subset

let value: HashSet<i32> = [1, 2, 3].into();
verify_that!(value, superset_of([1, 2, 3]))?;  // Passes

Item multiplicity in both the actual and expected containers is ignored:

let value: Vec<i32> = vec![0, 0, 1];
verify_that!(value, superset_of([0, 1]))?;  // Passes
verify_that!(value, superset_of([0, 1, 1]))?;  // Passes

One can also verify the contents of a slice by dereferencing it:

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

A note on performance: This matcher uses a naive algorithm with a worst-case runtime proportional to the product of the sizes of the actual and expected containers as well as the time to check equality of each pair of items. It should not be used on especially large containers.